In-Memory Stateful Data Modeling
Asked of: Software Engineer
Last updated

What's being tested
These problems test stateful in-memory modeling: maintaining mutable domain objects, applying commands in order, and returning correct query results after many updates. Interviewers are probing for clean data-structure design, deterministic tie-breaking, predicate evaluation, and careful handling of partial state changes.
Patterns & templates
-
Command dispatcher — parse tokens once, route via
execute(command), keep validation separate from mutation to avoid half-applied operations. -
Hash-indexed state — use
dict/HashMapfor tables, rows, orders, and IDs; targetO(1)lookup and update. -
Predicate evaluator — represent filters as small AST nodes or closures; support
AND/OR, comparison operators, and type-aware comparisons. -
Priority queues by side — buy book orders by max price then earliest time; sell book by min price then earliest time.
-
FIFO queues per price level — use
Dequefor price-time priority; matching isO(fills)afterO(log P)price-level lookup. -
Mutation ordering — compute match/fill/delete steps explicitly; update quantities before removing empty orders or price levels.
-
Stable tie-breaking — maintain monotonically increasing
timestamp/sequence number; never rely on unordered map iteration for deterministic output.
Common pitfalls
Pitfall: Treating an in-memory database like string filtering only; rows need schemas, typed values, missing-column behavior, and compound predicates.
Pitfall: Using one global heap for an order book without lazy deletion or ID tracking; canceled or partially filled orders can reappear incorrectly.
Pitfall: Forgetting partial fills; matching must handle buyer quantity, seller quantity, residual insertion, and exact exhaustion symmetrically.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
Related concepts
- In-Memory Stateful API DesignCoding & Algorithms
- Stateful In-Memory Data StructuresCoding & Algorithms
- Caching And Stateful Data Structure DesignCoding & Algorithms
- Mutable Data Structure DesignCoding & Algorithms
- In-Memory Databases And Query ProcessingSystem Design
- Stateful Data Structures And OOP API DesignCoding & Algorithms