SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
  • Scalability
  • Availability
  • Reliability
  • Single Point of Failure (SPOF)
  • Latency vs Throughput vs Bandwidth
  • Consistent Hashing
  • CAP Theorem
  • Fault Tolerance and Redundancy
  • Failover
  • Stateless vs Stateful
  • Concurrency vs Parallelism
  • Capacity Planning
  • Back Pressure
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Foundations/Core Concepts

Back Pressure

When a consumer is too slow, push back on the producer instead of letting everything pile up.

⏱ 12 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Back pressure is a way for a slow part of a system to push back on a fast part, instead of letting work pile up until something breaks.

  • When a producer sends work faster than a consumer can handle, a queue grows between them.
  • A queue with no limit keeps growing: memory fills up, every item waits longer and longer, and finally the service crashes.
  • With back pressure, the consumer says "slow down" (or the queue refuses new work), so the system stays healthy under overload.

02Concept: What is it?

Think of two machines joined by a pipe. The first one (the producer) puts work in. The second one (the consumer) takes work out and does it. If the consumer is slower, the pipe slowly fills up. What should happen when it is full?

If the answer is "keep accepting everything", the buffer grows, the delay for each new item grows, and eventually the process runs out of memory. This is the quiet danger of unbounded queues. Back pressure is the set of ideas that avoids it: limit the buffer, and tell the sender about the limit.

Without and with back pressure
No back pressure
πŸ“€Producer150 / s
→↓all accepted
πŸ“šQueuegrows forever
→↓
βš™οΈConsumer100 / s
Delay for new itemskeeps rising, then crash
With back pressure
πŸ“€Producerslowed to 100 / s
↔slow down
πŸ“šQueuesmall limit
→↓
βš™οΈConsumer100 / s
Delay for new itemssmall and steady
Without it, the queue is the thing that breaks. With it, the pressure travels back to the source.
🧠A full queue is a message
A queue that is full is not a problem to hide. It is information: "the consumer cannot keep up." Back pressure is about passing that message back to the sender, so it can wait, slow down, or give up.

03Real-Life Example

🍡The Sushi Conveyor Belt
A chef puts plates on a conveyor belt faster than the diners can eat. If the belt is endless, plates pile up at the end, the oldest sushi is stale by the time it is eaten, and finally the belt jams. A smarter restaurant has a short belt. When the belt is full, the chef stops and waits until a spot is free (the chef is blocked). Or the diners press a button when they want a plate, and the chef only makes what is asked (pull). Or the chef throws away the extra plates (drop). Each choice is a kind of back pressure.
Sushi restaurant
Back pressure
The chef
The producer
The diners
The consumer
The belt
The queue or buffer
A short belt
A bounded queue
The chef waits for a free spot
Blocking the producer
Diners press a button to ask for a plate
Pull or credit-based flow
Throwing extra plates away
Dropping work (load shedding)
A belt that never ends and jams
An unbounded queue that runs out of memory
The pressure travels backwards
πŸ™‹Usertold to wait or retry
←429 / 503
πŸšͺAPIlimits work in flight
←
πŸ“šQueuefull
←
πŸ—„οΈDatabasethe slow part
Each slow part pushes on the part before it, all the way to the user.

04Why Do We Need It?

πŸ’₯Avoid crashes
A bounded buffer cannot use up all the memory, so the service stays alive under overload.
⏱️Keep delays small
A long queue means every new item waits behind many others. A short queue keeps the wait short.
🧯Stop the chain reaction
One slow part can drag down everything upstream. Back pressure keeps the damage local.
πŸ“Predictable behaviour
You know what happens when you are overloaded: a clear 'wait' or 'no', not a mystery crash.
🀝Fair sharing
The producer can react: slow down, retry later, or send somewhere else.
πŸ”‹Use resources well
Work you cannot finish soon is better refused early than half-done late.
Every queue needs a limit, and every limit needs a rule for what happens when it is reached.

05Where Do We Use It?

🌐Network (TCP)
TCP flow control: a slow receiver advertises a small window, so the sender slows down. This is back pressure built into the network.
πŸ“¨Message queues and streams
Limits on queue length, consumer prefetch counts and consumer lag. Brokers can refuse or slow publishers.
🧡Thread pools
A bounded task queue plus a rejection rule (block the caller, or reject the task).
πŸšͺAPIs and gateways
Limit the number of requests in flight and return 429 or 503 with a retry hint.
🌊Stream processing
Reactive streams and stream engines let the consumer request how many items it can take.
πŸ“Pipes and files
A shell pipe blocks the writer when the reader is slow. Same idea, very old.

06Types / Parts / How It Works

Four ways to react when the consumer is slower

The main strategies
1. Buffer (unbounded)
πŸ“šKeep everythingno limit
Riskmemory, delay, crash
2. Drop
πŸ—‘οΈThrow away extraload shedding
Risklost work
3. Block / push back
βœ‹Make the sender wait429, 503, blocking
Riskslow producers
4. Pull / credits
🎟️Consumer asks for Nreactive streams
Riskmore design work
Dangerous Lossy Slows sender Controlled
They all answer one question: what do we do with the extra work?

The bars are an illustrative comparison of risk, not measurements.

StrategyHow it worksGood forWatch out for
Unbounded bufferAccept all, queue itSmall, short bursts you are sure aboutMemory use, rising delay, crash
Bounded + drop (load shedding)When full, discard new (or old) itemsWork that can be skipped: metrics, video frames, best-effort tasksData loss, so decide what to drop
Bounded + blockWhen full, the producer waits, or gets 429/503Work that must not be lostProducers must handle waiting or retries
Pull / credit-basedConsumer requests N items at a timeStreams with steady flow and clear ownershipNeeds both sides to support the protocol

Real forms you will meet

FormExample
Network flow controlTCP window: the receiver tells the sender how much it can accept
HTTP status codes429 Too Many Requests and 503 Service Unavailable, often with a Retry-After header
Bounded queuesA thread pool with a small queue and a rejection policy
Prefetch / creditsA message consumer that takes only a few unacknowledged messages at a time
Reactive streamsA subscriber requests n items, and the publisher never sends more than requested
VisualizerProducer faster than consumer: four ways to reactMake the producer faster than the consumer, then switch between the strategies. Watch the unbounded queue crash, the drop strategy lose work, and block and pull keep things steady. Try the burst.
What happens when the consumer cannot keep up?

Everything is accepted and queued. The queue has no limit, so memory is the only limit.

The queue limit is used by the two bounded strategies. Pull keeps about 0.2 s of work in flight.
Items waiting in the queue, each second (red = the service has crashed)
Delay for a new item (time spent waiting + working)
Requests that failed per second
0 s15 s30 s
Peak queue
1050
items waiting
Peak delay
10.5 s
for a new item
Lost in the crash
2400
requests
Served
2100
finished in 30 s
Service
crashed at 21 s
memory limit 1000 items
The queue grew without limit. At second 21 it passed 1000 items and the service ran out of memory. Everything in the queue was lost, and every request after that failed too.

A simplified model with a simulated clock (no random numbers) and made-up round numbers, so treat it as illustrative. Each second the consumer works through the queue, then new items arrive, and whatever does not fit is handled by the strategy you chose.

07How to Use It / Steps / Implementation

Adding back pressure to a system

  1. 1
    Find every queue
    Look for lists, channels, thread-pool queues, message topics and buffers. Many are hidden in libraries, and their default limit may be 'none'.
  2. 2
    Bound them
    Give each queue a maximum size. Pick the size from how much delay you can accept, not from how much memory you have.
  3. 3
    Decide what happens when full
    Block the sender, reject with 429 or 503, or drop the least important work. Make the rule explicit.
  4. 4
    Pass the signal back
    Make sure the producer can see the message: a blocking call, an error code with Retry-After, or a credit protocol.
  5. 5
    Let producers react
    Producers should slow down, retry with backoff and jitter, or fail cleanly, and not retry in a tight loop.
  6. 6
    Limit work in flight
    Cap the number of concurrent requests per service, so it never takes more than it can finish.
  7. 7
    Protect what matters
    Shed low-priority work first (analytics, thumbnails) and keep payments and logins alive.
  8. 8
    Watch the signals
    Track queue length, wait time, rejected and dropped counts, and consumer lag. Alert on a queue that stays long.
πŸ’‘Short queues are healthy
A queue is meant to absorb short bursts, not to store a long backlog. If it stays full for minutes, the system needs more capacity, a faster consumer, or less incoming work.
⚠️Retries can make it worse
If every client retries at once when told to wait, the load comes back in a wave. Use exponential backoff with random jitter, and respect Retry-After.

08Key Terms to Know

TermMeaning in easy words
ProducerThe part that creates work and sends it on
ConsumerThe part that receives work and does it
Queue / bufferA waiting line between producer and consumer
Bounded queueA queue with a fixed maximum size
Unbounded queueA queue with no size limit, so only memory limits it
Back pressureA signal or rule that makes the producer slow down when the consumer is overloaded
Load sheddingDeliberately dropping some work so the rest can be done well
Flow controlControlling how fast data is sent, as TCP does with its window
Consumer lagHow far behind the consumer is, in items or in time
Credit / demandThe number of items a consumer says it is ready to receive
429 / 503HTTP status codes that mean 'too many requests' and 'service unavailable'

09Pros, Cons and Trade-offs

βœ… Pros
  • Protects memory and avoids crashes under overload
  • Keeps delays small and predictable
  • Stops a slow part from taking down the whole chain
  • Gives producers clear information to act on
  • Works at many levels: network, thread pool, API, stream
⚠️ Cons
  • Producers must be able to wait, retry or fail
  • Dropped work is lost, so some data may be missing
  • Blocking can spread slowness upstream
  • Harder to design than 'just queue it'
  • A bad limit can refuse work too early or too late

Trade-offs

ChoiceWe gainWe lose
Small queueLow delay and low memory useLess room for bursts, so more rejections
Large queueAbsorbs bigger burstsLong delays, and a bigger crash when it overflows
Drop when fullFast and simple, protects the consumerLost work
Block when fullNo lost workSlowness moves to the producer and its callers
Reject early (429/503)Fast, clear feedback to clientsUsers see errors, so clients need retry logic
Pull / creditsFine control, steady flowMore complex protocol on both sides

10Common Problems and Mistakes

Common mistakes

  1. Unbounded queues by default. Many libraries default to "no limit". It works in tests and fails in production.
  2. Hiding the signal. Swallowing errors or silently dropping, so the producer never learns it is overloading the consumer.
  3. A queue that is too big. It turns an overload into minutes of delay, with old work that nobody wants any more.
  4. Retry storms. Clients retry at once, with no backoff, and make the overload worse.
  5. Dropping the wrong work. Dropping payments to save analytics, instead of the other way around.
  6. Blocking the wrong thread. A blocked event-loop or request thread freezes unrelated work.
  7. No monitoring. A full queue is invisible until users complain.

Things to watch

πŸ•°οΈStale work
Items that waited too long may no longer be useful. Add time limits (TTL) and skip expired work.
πŸ”Duplicates
When clients retry after a timeout, the same work may arrive twice. Make handlers idempotent.
πŸ”—Chains of queues
Back pressure must travel through every stage. One hidden unbounded queue breaks the chain.
βš–οΈFairness
One noisy client can fill a shared queue. Use per-client limits as well.

11Real-World Examples

🌐TCP
A receiver that cannot keep up shrinks its window, and the sender slows down. This is back pressure that you use every day.
🐚Unix pipes
If the reader is slow, the writer is blocked. No data is lost and memory stays small.
πŸ“¨Message brokers
Consumers limit unacknowledged messages (prefetch), and brokers can slow or block publishers when memory or disk is high.
🌊Reactive streams
A standard where the subscriber requests n items, which builds demand-based back pressure into the API.
πŸšͺAPI gateways
Limit in-flight requests and answer 429 or 503 with Retry-After when the backend is full.
πŸ“ˆMetrics pipelines
Often drop the oldest or least important samples under pressure, since a few lost points are acceptable.
πŸ“Note
Each product has its own settings and defaults. Check the documentation for the version you use.
Mini case: an upload service
πŸ“±Clientsburst of uploads
→↓requests
πŸšͺGatewaymax 200 in flight
→↓accepted
βš™οΈWorkersbounded queue
←429 + Retry-After
Without a limit the service dies. With a limit it stays up and tells clients to wait.

12Related Topics to Read Next

Message Queues→

The most common place where a queue needs a limit.

Rate Limiting→

A way to cap how much work enters the system.

Capacity Planning→

Back pressure is the safety net when demand beats your plan.

Circuit Breaker→

Stops calls to a failing service, a close cousin of back pressure.

Dead Letter Queues→

Where work goes when it keeps failing.

TCP vs UDP→

TCP has flow control built in.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”Problem: producer faster than consumer, so the queue grows.
  • βœ”Unbounded queue: memory fills, delay rises, crash. Avoid it.
  • βœ”Fix: bound the queue and decide what happens when it is full.
  • βœ”Options: drop (shed), block or reject (429/503), pull with credits.
  • βœ”Signal: pass the message back to the producer, all the way upstream.
  • βœ”Clients: retry with backoff and jitter, and respect Retry-After.
  • βœ”Watch: queue length, wait time, drops, consumer lag.
  • βœ”One line: β€œNever accept more work than you can finish, and tell the sender when you are full.”
← Previous
Capacity Planning
Next β†’
OSI Model