Build a Fixed-Size Object Pool With an Intrusive Free List
Last updated: November 29, 2026
Quick Overview
Implement a pool that preallocates N slots for request objects in a high-QPS frontend server, hands them out and takes them back in O(1) using a free list stored inside the unused slots, and detects double frees.
0
0
0 solved
Implement a pool that preallocates N slots for request objects in a high-QPS frontend server, hands them out and takes them back in O(1) using a free list stored inside the unused slots, and detects double frees.
Latency-sensitive Google servers such as ads serving avoid per-request heap allocation to cut allocator contention and GC or fragmentation pauses. The interviewer checks that you can implement the classic free-list trick and reason about safety bugs like double free and use after free.
What the Interviewer Expects
- Preallocate storage and keep a free list for O(1) acquire and release
- Store the next pointer inside free slots instead of a side structure
- Detect double free and foreign handles
- Decide what happens when the pool is exhausted
- Explain when a pool helps and when it hurts
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you make this thread safe without one global lock?
- How do generation counters catch use after free?
- How does this compare to tcmalloc's per-thread caches?
- What happens to memory if a burst grows the pool and traffic drops?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
ObjectPool(capacity, factory)buildscapacityobjects up front.acquire()returns a handle(index, generation)in O(1); raisesPoolExhaustedwhen empty.get(handle)returns the objec...
High-Level Design
The free list is a singly linked list threaded through an array next_free, where next_free[i] is the index of the next free slot and -1 ends the list. Acquire pops the head; release pushes. In C...