Library / Case Studies

Deduplication at Segment

The single requirement of all data pipelines is that they cannot lose data. Data can usually be delayed or re-ordered–but never dropped.

By Segment engineers · Segment · Added 2026-10-12

Open original source

All content belongs to Segment engineers / Segment. We only link to it and give credit. Report a problem

Learn this case study

About 37 min left. Your work is saved as you go.

What you are about to study

Segment explains a real system. You should know the basics: caching, queues and replication.

Ideas you will meet

Event Driven Architecture
Loosely coupled services reacting to events.
Distributed Systems
Consensus, time, failure and the fundamentals of scale-out.

What we already know about this

Our own lessons on these ideas. Read them here before you start, so it makes sense.

  • Messaging and Microservice Patterns · 12 minMessage brokers comparedQueues versus logs, and how Kafka, RabbitMQ, ActiveMQ, SQS, Pub/Sub and Pulsar differ, so you can pick one for a job.Read here

    Why brokers

    A message broker sits between producers and consumers so they do not need to be up at the same time, can run at different speeds and can scale separately. It gives you buffering (absorb bursts), decoupling, retries and fan-out. (The idea is introduced in the queues and async lesson of the foundations course.)

    Two families

    Queue-style brokerLog-style broker
    ModelMessages are routed to queues, delivered to a consumer, acknowledged and removedMessages are appended to a retained log; consumers track their own position
    ReplayNot normallyYes: re-read from any retained offset
    ConsumersCompeting workers share one queueSeveral groups read the same log independently
    OrderingPer queue, loosened by competing workersPer partition
    StrengthsRich routing, per-message acks, priorities, delaysHuge throughput, history, stream processing
    ExamplesRabbitMQ, ActiveMQ, Amazon SQSKafka, Pulsar (also queue mode), Kinesis

    Figure SDA-MSV-01-1 · Queue versus log · © forcsguy.com

    The common brokers

    • Kafka: distributed log; partitions give parallelism and per-key order; very high throughput; consumer groups; the foundation of many event pipelines and stream processors. More to operate (or use a managed service). Internals in the Kafka lesson of the advanced distributed systems course.
    • RabbitMQ (and ActiveMQ): classic brokers speaking AMQP and other protocols. Exchanges route messages to queues by rules (direct, topic, fanout, headers). Per-message acknowledgements, priorities, delays and dead letter handling. Excellent for task queues and flexible routing at moderate scale.
    • Amazon SQS: fully managed queue. Standard queues scale enormously with at-least-once delivery and best-effort ordering; FIFO queues keep order and deduplicate, at lower throughput. Visibility timeout and dead letter queues are built in. Pairs with SNS for fan-out.
    • Google Pub/Sub (and similar cloud services): managed, global pub/sub with subscriptions, acknowledgement deadlines and optional ordering keys.
    • Apache Pulsar: log-style with separated compute (brokers) and storage (BookKeeper), multi-tenancy, geo-replication, and both streaming and queue-style subscriptions.

    Delivery guarantees

    • At most once: may lose, never duplicates (acknowledge before processing). Fine for metrics.
    • At least once: no loss, possible duplicates (acknowledge after processing); the practical default. Consumers must be idempotent.
    • Exactly once: really means at-least-once delivery plus deduplication or transactions, available within some systems (for example Kafka transactions), but end-to-end it requires idempotent consumers or transactional sinks.

    Choosing

    Figure SDA-MSV-01-2 · Which broker family · © forcsguy.com

    NeedLean towards
    Simple background jobs, no opsSQS or a cloud queue
    Flexible routing, priorities, delaysRabbitMQ
    High-volume event streaming, replayKafka or Pulsar
    Fan-out to many consumers in a cloudPub/Sub or SNS plus queues
    Stream processing and joinsKafka with Flink or Kafka Streams

    Questions that decide it

    How many messages per second, and how large? Do you need ordering (and by what key)? Do you need replay? How many independent consumers? What latency? Who will operate it? Start with the simplest tool that meets the needs; moving to a streaming platform when you truly need replay and scale is easier than operating one you did not need.

    Real-world reading

    Open this lesson with its quiz and exercise

Go deeper on this

A path through videos, articles, other case studies and code on the same ideas as Deduplication at Segment.

  1. Warm upGet the vocabulary first.

  2. WatchHow others solve the same problem, on video.

    Videos belong to their creators and play from YouTube. More on YouTube (opens in a new tab)

  3. ReadEngineers explain it in their own words.

  4. See it in another companyThe same ideas, a different system.

  5. Read the codeSee how it looks when it is real.

Keep learning

Loading community…