When designing a system in an LLD round, isolate mutable state inside domain entities, bound every in-memory collection and lock scope, and hide varying rules behind small interfaces so concurrent callers cannot corrupt state or exhaust memory.
TL;DR30-second simplified summary▾
The Core Idea (Intermediate): Production LLD balances clean extensibility with bounded memory, deterministic Clock testing, and per-entity lock granularity.
Key Trade-Offs: Choose ConcurrentHashMap.compute() or ReadWriteLock for entity-level concurrency, use long IDs/offsets to avoid overflow, and back event buses with bounded queues.
Boundary Rule: Do not abstract single-implementation rules prematurely.
Bounded Queues, Clock Injection, and Per-Entity Locks.
Why this matters: Make designs testable and safe under concurrent callers.
Use State for explicit lifecycles (CREATED -> ACTIVE -> COMPLETED), ArrayBlockingQueue for event-bus backpressure, Clock injection for TTL/rate-limit tests, and ConcurrentHashMap.computeIfAbsent / per-entity ReentrantLocks instead of a global synchronized lock.
Deterministic State Transitions
Explicit state transitions prevent half-mutated objects when validation or locking fails.
Practice: Make the trade-off yourself.
Why should an in-memory LLD Event Bus use a bounded queue and a shared worker pool instead of spawning one thread per subscriber or using an unbounded LinkedBlockingQueue?
How to Prepare for LLD Round
Great LLD is not memorizing 23 GoF patterns—it is isolating mutable state, bounding collections and lock scopes, and keeping extension points behind small interfaces.