DBRaven
Pattern · resilience

Backpressure

established

Summary

A flow control mechanism where a downstream system signals its capacity limit to upstream producers, causing them to slow or pause ingestion rather than accumulating unbounded queues that eventually exhaust memory or corrupt data.

Problem

A producer-consumer system where production rate can exceed consumption rate will eventually overflow any fixed-size intermediate buffer, causing data loss or out-of-memory failure. A bounded buffer without backpressure either drops messages or blocks the producer: the latter causing latency to propagate upstream.

Description

In any producer-consumer pipeline, if the producer can emit faster than the consumer can process, one of three things happens: (1) an intermediate buffer absorbs the excess until it overflows, (2) messages are dropped, or (3) the producer is asked to slow down. Backpressure implements option 3.

A backpressure signal travels upstream: a consumer that is approaching capacity : measured by queue depth, memory usage, or processing latency: notifies the producer to reduce its emission rate or pause entirely. The producer holds or delays new work rather than adding it to the queue. When the consumer drains to a healthy level, it signals the producer to resume.

In reactive streams (RxJava, Project Reactor, Akka Streams), backpressure is a first-class protocol: consumers request N items from producers; producers emit at most N items before waiting for another request. In Kafka consumer groups, lag monitoring and pausing the consumer's poll loop implements a similar effect. In HTTP, the server returning 429 Too Many Requests or the TCP receive window shrinking to zero are backpressure signals at the protocol level.

Without backpressure, a producer running faster than its consumer will eventually exhaust buffers (out-of-memory crash), trigger unbounded latency growth, or cause data loss via buffer overflow and message dropping.

Reactive Streams (JVM): implement the Reactive Streams spec: Publisher emits only when Subscriber requests via request(n). Project Reactor, RxJava, and Akka Streams all implement this protocol natively.

Kafka: monitor consumer group lag. When lag exceeds a threshold, pause the consumer (consumer.pause()) and resume when lag drops. The Kafka producer will not stall on its own; backpressure in Kafka is typically implemented by slowing down the downstream processing pipeline that feeds the producer, not by signaling the broker.

gRPC: flow control is built into HTTP/2, the receive window limits in-flight data; the server can signal GOAWAY or return RESOURCE_EXHAUSTED to slow callers.

Queue-backed systems: use bounded queues (ArrayBlockingQueue in Java) with caller-blocks-on-full semantics. The producer thread blocks when the queue is full, providing natural backpressure to the calling thread.

Tradeoffs

Memory safety
+0.8

Prevents out-of-memory failures from unbounded queue growth

Flow control
+0.7

Provides end-to-end flow control: slow consumers naturally throttle fast producers

Admission control
+0.6

Enables capacity-based admission control; work is only accepted when it can be processed

Data integrity
+0.7

Preserves data integrity: no silent message dropping

Coupling
-0.3

Requires a bidirectional communication channel between consumer and producer

Producer-side complexity
-0.3

Adds producer-side state (paused/active) and logic to respect backpressure signals

Latency
-0.2

Latency is introduced at the producer when it must hold or delay work

Throughput visibility
-0.1

System-wide throughput is bounded by the slowest stage; backpressure makes this visible, not worse

When to use

Producer can emit faster than the consumer can process

If the rates are always balanced, backpressure machinery adds complexity with no benefit

Data loss or unbounded latency is unacceptable

Dropping messages or blocking without limit are the alternatives to backpressure

Processing is done through a pipeline with multiple stages

Multi-stage pipelines need backpressure at each stage boundary to prevent accumulation at any one stage

Consumers have variable processing rates (e.g., due to GC, I/O, downstream API calls)

Variable consumption rate creates bursty backpressure signals: the pipeline must handle these gracefully

When not to use

The producer rate is always bounded below the consumer rate with a known safety margin

Backpressure adds protocol overhead and producer-side complexity; unnecessary if rates are controlled

Message loss is acceptable (e.g., metrics sampling, best-effort telemetry)

Dropping messages is simpler and lower-latency than backpressure signaling

The pipeline is fire-and-forget with no producer-consumer coupling

Cannot implement backpressure without a feedback channel from consumer to producer

Operational Requirements

mandatory

Monitor backpressure events as a leading indicator of capacity pressure

Frequent backpressure signals mean a consumer needs scaling.

recommended

Set backpressure thresholds conservatively

Trigger at 70-80% capacity, not at 100%, to leave headroom before overflow.

mandatory

Implement producer-side retry with jitter when resuming after backpressure

Simultaneous resumption can cause a burst that immediately retriggers backpressure.

mandatory

Bound the in-flight message count in distributed systems

Backpressure signals have latency; the producer may still emit after the consumer has paused.

Characteristics

Scales on
Implementation complexitymedium
Operational complexitymedium

Relationships

Complements

competing consumerscircuit breakerretry with backoff

Basis

Well-understood flow control pattern with formal specification in Reactive Streams; documented implementations in Kafka, Akka, gRPC, and Java concurrency libraries

Related Architecture Knowledge

Outbound: this entity affects

ComplementsPattern
circuit breaker
Grounded

Backpressure controls the rate at which producers emit to consumers; circuit breakers fast-fail calls to overloaded downstream services. Together they provide complete flow control for both producer-consumer and request-response topologies.

Full relationship →
MitigatesFailure Mode
queue backlog accumulation
Grounded

Backpressure prevents queue backlog accumulation by signaling producers to slow or pause ingestion when the consumer is approaching capacity, ensuring the queue depth stays bounded rather than growing without limit.

Tradeoffs

  • ·Backpressure reduces throughput at the producer during capacity pressure; some use cases require drop instead of block
Full relationship →
MitigatesFailure Mode
slow consumer
Draft · unverified

Backpressure prevents slow consumers from falling further behind by signaling producers to pause, giving the consumer time to drain its backlog before new messages arrive.

Full relationship →

Inbound: affects this entity

SupportsTechnology
kafka
Grounded

Kafka consumer groups implement backpressure via the consumer poll loop: pausing the poll loop stops consumption without dropping messages, providing durable backpressure to the producer.

Full relationship →
Benefits FromWorkload
realtime collaboration workload
Grounded

Real-time collaboration workloads with unpredictable write bursts benefit from backpressure to prevent the sync server from being overwhelmed by simultaneous edit storms.

Full relationship →
Benefits FromWorkload
write heavy transactional
Draft · unverified

Write-heavy transactional workloads benefit from backpressure to prevent upstream services from overloading the write path during traffic bursts.

Full relationship →

Used In Architecture Scenarios

Distributed Job Queue Platformmoderate

Write-Heavy Application

A durable background job execution platform where jobs are enqueued via API and executed by competing consumer worker pools. PostgreSQL is the durable job store, job definitions, retry state, scheduling metadata, and dead-letter records persist in PostgreSQL with ACID guarantees, surviving any worker or queue infrastructure failure. Redis tracks in-flight job state (which worker claimed which job, visibility timeout lease expiry) to enable fast lease checks without PostgreSQL queries on the hot path. Temporal provides workflow orchestration for multi-step jobs that require coordination across multiple execution stages, with built-in state machine semantics and durable activity execution. Kafka carries job completion events to downstream consumers (analytics, billing triggers, notification fan-out). Backpressure between the job enqueue rate and worker execution rate prevents runaway job accumulation when workers are degraded.

Gaming Backend Platformhigh

Realtime Collaboration

An online multiplayer game backend built around authoritative server game state synchronization. Game rooms run as distributed state machines where the server is the single source of truth for game state: client predictions are reconciled against the server state at every tick. WebSocket connections provide low-latency bidirectional communication for state deltas. Redis stores active game room state (in-flight, with sub-millisecond access), session affinity tokens (routing players to the same server instance as their game room), and matchmaking queues. PostgreSQL is the durable store for player profiles, persistent inventory, leaderboards, and achievement records. Kafka carries post-game event streams for analytics, anti-cheat processing, and achievement evaluation. NATS provides low-latency pub/sub for intra-cluster game state broadcasting when multiple game server instances must coordinate on shared state. Event sourcing records every game action as an immutable event for replay, dispute resolution, and anti-cheat audit.

Geospatial Tracking Platformhigh

Realtime Collaboration

A real-time location tracking platform for moving entities: vehicles, delivery couriers, field workers, and assets: receiving position updates at 1–30 second intervals from thousands of simultaneously tracked objects. Redis geospatial indexes (GEOADD / GEOSEARCH) serve sub-10ms proximity queries against the live position surface; PostgreSQL stores durable entity metadata and historical location records; TimescaleDB stores high-frequency time-series location data with automatic hypertable chunking and retention policies; Kafka streams location events to downstream consumers (dispatch systems, customer tracking apps, analytics pipelines). Geofence evaluation runs at ingestion time: each incoming position update is tested against active geofences for the entity's region, and geofence entry/exit events are emitted as Kafka messages to downstream consumers.

IoT Telemetry Ingestion Platformhigh

Write-Heavy Application

A high-rate device telemetry ingestion architecture designed for millions of devices emitting metrics at 1–60 second intervals. Kafka absorbs device writes as an ingestion buffer, decoupling device-facing ingest endpoints from the storage write path so that downstream storage pressure never propagates back to devices. TimescaleDB provides time-series storage with automatic chunk partitioning by time range, native compression, and continuous aggregate views for rollup queries. ClickHouse serves as the OLAP layer for device fleet analytics queries. Redis caches last-known device state (current readings per device) for real-time alerting queries that must not scan historical storage. Backpressure on the Kafka consumer side prevents storage write throughput from being overwhelmed by burst ingestion events from device reconnect storms.

Observability Platformhigh

Analytics Pipeline

A metrics, logs, and traces ingestion and query platform built to absorb the telemetry output of a production system fleet: including the telemetry volume spikes that accompany the incidents the platform is meant to detect. ClickHouse stores metrics data with automatic time-based rollup via continuous materialized views; TimescaleDB provides complementary time-series storage for high-cardinality alert evaluation; Kafka buffers the ingestion stream against downstream write pressure, decoupling ingest acceptance rate from storage write throughput; Elasticsearch serves log full-text search and structured field filtering; Redis caches dashboard query results and active alert state for sub-100ms alert evaluation latency. The alert engine evaluates threshold and anomaly rules against pre-computed materialized views, not raw data, to bound alert evaluation cost independent of ingestion volume.

Streaming Media Platformhigh

Event-Driven System

A video and audio streaming architecture where content ingestion triggers an async multi-variant transcoding pipeline, CDN delivery handles 95%+ of playback traffic, and Cassandra absorbs the write volume of per-user viewing history. Kafka decouples upload events from transcoding workers; MinIO stores raw and encoded assets; Redis maintains playback session state and view counters. The architecture must handle upload spikes without blocking delivery, and cache cold starts without cascading database load.