LLD Guide · Module 2: Problem prep · Lesson 02.02

Prep: Employee Management System (In-Memory)

CRUD looks trivial until you keep three indexes in step under concurrency, at sub-millisecond latency.

By Cruscible Engineering · Published

The hard part isn't storing employees. It's that one employee lives in several places at once, and every change has to move it in all of them together.

This lesson prepares you for Build an Employee Management System (In-Memory). It doesn't solve it.

1. What the employee management contract asks for

An in-memory store of employees with lookups by id, department, role and partial name, per-department salary statistics, and promotions. Nothing leaves the JVM: no database, Redis or files.

MethodSuccessNot found / empty
addEmployee(name, dept, role, salary)a new unique id—
getEmployee(id)the employee mapnull
updateEmployee(id, dept, role, salary)true; only non-null arguments changefalse
removeEmployee(id)truefalse
getByDepartment / getByRole / getAllEmployeesa list of employee mapsan empty list, never null
searchByName(query)case-insensitive partial matchesan empty list
getDepartmentStats(dept)count, avgSalary, minSalary, maxSalary, totalSalarycount 0 and every salary 0.0
promoteEmployee(id, newRole, increase)true; new role and salary + increasefalse
getEmployeeCount()the number of employees0

Every employee map has exactly the keys id, name, department, role and salary, with salary as a Double. The statistics map's count is an Integer.

2. Lessons to read before the employee management

3. Employee management design decisions to make first

  1. What are your indexes? You need fast lookup by id, and lists by department and by role. Which structure backs each, and what do they store: whole employees, or ids?
  2. What moves when a department changes? Walk through updateEmployee(id, "Sales", null, null) for someone in Engineering. Which indexes change, and in what order?
  3. What makes promoteEmployee atomic? It reads the salary and writes a new one. What stops two promotions at the same moment from losing one raise?
  4. How do you avoid one global lock? The performance target is 50,000 operations a second at under 1 ms P99. Which operations can run in parallel, and which must not overlap?
  5. What does a read return? If you hand out the employee object you store, can a caller change your data through it?
  6. How are ids generated so two threads never get the same one?

4. Employee management pitfalls

⚠️ Trap: a partial update must ignore null arguments. updateEmployee(id, null, null, 90000.0) changes only the salary, and it still returns true.

⚠️ Trap: statistics for an empty or unknown department are zeros (0 and 0.0), not null and not NaN from dividing by zero.

⚠️ Trap: an employee who changes department or role must disappear from the old index and appear in the new one. A stale index entry shows up in the wrong list.

⚠️ Trap: name search is case-insensitive and partial: "ali" finds "Alice".

💡 Tip: you may skip the injected KV store and use your own collections.

💡 Tip: return copies (new maps) from every read. Then no caller can change your stored data, and no reader sees a half-finished update.

Before you submit

Further reading

After you've tried it

Submit first. The full walkthrough of one solution: Building an Employee Management System in Pure Java.

Open the problem