ring buffer
A fixed-size array used as a loop: when writes reach the end they wrap to the start, overwriting the oldest data.
In more detail
A head index marks the oldest item and a tail index the next write position, and both advance with modulo arithmetic. Memory is allocated once and never grows, which suits streams of sensor readings, logs and audio. It always holds the most recent capacity-many values.
Example
An SSE server replays recent events from a ring buffer to reconnecting clients.Related terms
- wraparound — Moving an index past the last slot of an array back to slot zero, usually computed as (index + 1) % capacity.
- modulo — The operation that gives the remainder after division, written % in many programming languages, so 17 % 5 is 2.
- maxlen — An optional deque setting that caps its length; once full, adding at one end silently drops an item from the other end.
- sliding window — The most recent k items of a sequence or stream, which moves forward one item at a time as new data arrives.
- capacity — The number of items a structure has room for before it must grow, as opposed to the number it currently holds.
- eBPF — A Linux kernel feature that runs small, verified programs inside the kernel when events such as system calls happen.
- Falco — An open-source runtime security tool that watches system calls on each node and raises alerts when they match rules.
- Last-Event-ID — The header a Server-Sent Events client sends when reconnecting, carrying the id of the last event it received so the server can continue from there.
- Server-Sent Events — A standard way for a server to keep an HTTP response open and push a stream of text events to the client, in one direction only.
Taught in
- Deques And Ring Buffers — Algorithms & Data Structures for Working Engineers
- Choosing The Right Sequence — Algorithms & Data Structures for Working Engineers
- Runtime Anomaly Detection with Falco & eBPF — Cloud Security & DevSecOps Engineering
- Server-Sent Events: Streaming Updates & Recovery — Production Full-Stack Engineering