Order and Deduplicate Out-of-Order Conversation Events per Call

Last updated: November 29, 2026

Quick Overview

Conversation events (utterances, hints, metadata) arrive at a consumer duplicated and out of order. Implement a per-conversation reorder buffer that delivers events strictly in sequence, drops duplicates, and skips a missing sequence number after a timeout or when the buffer fills.

Cresta
Software Engineering Fundamentals
Software Engineer
Cresta
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


Conversation events (utterances, hints, metadata) arrive at a consumer duplicated and out of order. Implement a per-conversation reorder buffer that delivers events strictly in sequence, drops duplicates, and skips a missing sequence number after a timeout or when the buffer fills.

Cresta's streaming pipeline fans conversation events through message queues to the agent desktop, analytics, and QA, and at-least-once delivery means consumers must handle duplicates and reordering. The interviewer checks correctness under retries, bounded memory, and a deliberate choice between waiting for a gap and moving on.

What the Interviewer Expects
  • Explain why at-least-once delivery produces duplicates and reordering
  • Use a min-heap per conversation keyed by sequence number
  • Drop duplicates both already delivered and still buffered
  • Bound memory and latency with buffer size and gap timeout
  • Make the timeout testable by injecting time
Key Topics to Cover
At-least-once delivery
Idempotency
Heaps
Backpressure
Stream processing
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you persist next_seq so a restarted consumer does not redeliver?
  • When is it better to block forever on a gap instead of skipping?
  • How do you clean up state for conversations that have ended?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Each event has (conversation_id, seq, payload), with seq starting at 0 per conversation. Deliver to a callback in increasing seq with no gaps unless a gap is abandoned. Drop events with seq al...

High-Level Design

Per conversation keep next_seq, a min-heap of buffered events, and a set of buffered seqs. On arrival: drop if stale or duplicate, push, then drain the heap while its head equals next_seq. Track w...


Submit Your Answer
Markdown supported

Related Questions