Bounded Ring Buffer With Credit-Based Backpressure Between Routers
Last updated: November 29, 2026
Quick Overview
Implement a fixed-capacity FIFO ring buffer for a receiving router, and a link abstraction where the sender holds credits equal to free receiver slots, so sends block (return False) instead of overflowing.
Cerebras
November 29, 20260
0
0 solved
Implement a fixed-capacity FIFO ring buffer for a receiving router, and a link abstraction where the sender holds credits equal to free receiver slots, so sends block (return False) instead of overflowing.
Cores on a 2D fabric pass small messages through fixed-size router queues, and credit-based flow control is how such networks avoid dropping data. Runtime and firmware candidates get this to show careful index arithmetic, invariants, and an understanding of backpressure.
What the Interviewer Expects
- Implements push and pop in O(1) with head and size (or head and tail plus a count)
- Distinguishes empty from full correctly
- Keeps credits equal to free slots as an explicit invariant
- Explains what happens when credits are lost or duplicated
- Discusses thread-safety or the single-producer single-consumer case
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 lock-free for one producer and one consumer?
- What if credit returns travel on a link with latency? How big must the buffer be to sustain full bandwidth?
- How can credit-based flow control deadlock in a mesh, and how do virtual channels help?
- How would you test this for off-by-one bugs?
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
RingBuffer(capacity) with push (error when full) and pop (None when empty). Link(capacity) with try_send(item) that returns False when the receiver has no room, and consume() that pops and returns...
High-Level Design
Store head and size rather than head and tail, which avoids the classic empty-versus-full ambiguity when head equals tail. The write position is (head + size) % cap. The link's sender keeps `cre...