Data Structures & Algorithms · Interview question

What is a ring buffer and why is it the go-to structure for a UART ISR?

A strong answer

A ring buffer is a fixed-size array treated as circular, with a head index where the producer writes and a tail index where the consumer reads, both wrapping back to 0 when they pass the end. It's ideal for a UART RX ISR because it meets every constraint: fixed memory (no heap, sized at compile time), FIFO ordering (bytes come out in arrival order), O(1) push and pop with no data shifting (critical at high baud, you can't afford an O(n) memmove per byte), and a clean producer/consumer split where the ISR writes and the main loop reads. The data never moves; only the indices advance. That combination, bounded memory, constant-time, and a natural one-writer/one-reader division, is exactly what an interrupt-driven byte stream needs.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Ring Buffers

The fixed-memory FIFO behind every UART driver: head and tail indices wrapping a static array, O(1) push/pop, and the full-vs-empty trick, plus the lock-free single-producer/consumer pattern.

More Ring Buffers questions

Browse all 472 interview questions