Video in progress

The current system runs on RabbitMQ and the decision was made to move to Kafka. How do you plan a zero-downtime migration?

Step by step, one flow at a time: first the producers write to both systems (or there's a bridge), the consumers move to Kafka one by one and the results are compared, and at the end the RabbitMQ path is removed. The main risks are semantic differences (ack, ordering, retry) and duplicates during the migration.

📖 Answer

First an inventory: which exchanges and queues exist, who writes, who reads, and which RabbitMQ features are in use (priority, TTL, delayed exchange, RPC reply-to). These have no direct equivalent in Kafka, and each needs its own solution. This is where you find that some flows (RPC, for example) shouldn't be migrated at all.

Migration for each flow:

  1. A bridge or dual publish. The safest is a bridge from RabbitMQ to Kafka (the Kafka Connect RabbitMQ source connector or a small service). The producers don't change, and messages appear in Kafka. Dual publish (the producer writes to both) brings back the dual-write problem; it's acceptable only for a short time.

  2. A shadow consumer. A new consumer reading from Kafka writes its result somewhere separate, and it's compared with the old one. This is where the differences show up: ordering (in Kafka it's by key, so you have to pick the key correctly), retry semantics, message format.

  3. Switching the consumer. The old consumer is stopped, and the new one starts from an exact point. During the crossover the same message can be processed from both sides, so idempotency has to be in place beforehand. If the event ID is the same in both systems, dedup is easy.

  4. Moving the producer. Once all the consumers are on Kafka, the producer writes directly to Kafka and the bridge is removed.

  5. Cleanup. Watch the empty queues, and if no message arrives for a week or two, delete them.

Have a rollback plan for every step: the ability to switch a consumer back to RabbitMQ with a feature flag. And start with a low-risk flow (notifications), leaving the money-related ones for last; the team learns a lot in the first two flows.

Ask one more question up front: "why are we migrating?". If the answer is "Kafka is more modern", the migration probably isn't worth the cost.