Ring buffer (circular buffer)
A fixed-size array used as a queue whose write position wraps around, so memory stays bounded and the oldest data is overwritten or new data waits.
A ring buffer is an array with a read position and a write position. Both move forward and wrap to the start at the end, so the array behaves like an endless queue in a fixed amount of memory. There is no allocation per item, which makes it fast and predictable.
When it fills up, the design has to choose. Overwriting the oldest entries suits recent logs, metrics, audio and the Linux kernel log you read with dmesg: you always have the last N entries. Blocking or rejecting the writer suits data that must not be lost, which turns a full buffer into backpressure or load shedding. Telemetry agents and in-app log buffers use this shape so a burst cannot eat all memory.
The choice matters in incidents: a buffer that silently overwrites can drop exactly the log lines from the moment things broke.
Related terms
- Backpressure: A slow consumer signaling upstream to slow down, instead of buffering work until memory or the queue runs out.
- Load shedding: Rejecting some requests on purpose when a system is overloaded, so the rest still get served instead of everything grinding to a halt.
- Heap (priority queue): A tree kept just ordered enough that the smallest or most urgent item is always on top, with cheap inserts and removals.
- OpenTelemetry (OTel): An open, vendor-neutral standard and set of SDKs for producing and sending traces, metrics and logs.
