Integrations
Events with no loss and no duplicates
Queues connected services with each other and with external systems, and heavy background jobs went through them too. A lost or repeated message meant mismatched data.
Under NDA
This case study combines several projects with a similar problem. The companies’ names and logos are under NDA, and we left out the details that could identify them.
- Order
- events for one object are processed one after another
- Repeats
- delivering a message twice does not change the data
- Background
- heavy jobs do not hold up the user’s request
The problem
The exchange had to survive failures: no message is lost or processed twice, and where order matters, events are handled one after another.
What we did
01We described the message format in a shared contract that both sides work with.
02The message key is the object’s id, so its events stay in order, and handlers are idempotent: a duplicate creates no extra records.
03Messages that fail are set aside in a separate queue, an alert fires, and after a fix they can be replayed.
04Heavy operations moved out of the user’s request into background queues.
Result
The order of events is kept, there are no duplicates, and failed messages are not lost. Users don’t wait for heavy operations to finish.
Technologies
- Kafka
- NATS JetStream
- PostgreSQL
Check your own system
Three questions on this topic. After each one, a short note on why it matters.
Are events for one object processed strictly in order?
Why it matters
If events for one order land in different partitions, “canceled” can be processed before “paid”.
If the same message arrives twice, does the data stay correct?
Why it matters
Repeated delivery is normal for queues. Without idempotency it turns into a double charge or a duplicate record.
Are messages that failed to process kept, and does someone find out about them?
Why it matters
Without a DLQ and an alert, such a message is either lost or retried forever, blocking the queue.
Looks like this part is in order
If you want someone to look at the rest of the system from the outside, write to us.
There is something to check
Incidents usually start in places like these. Write to us about how this part of your system works, and we will suggest what to check first.
This is worth looking at first
There are several weak spots, and the rest of the system probably has some too. Write to us, and we will work out what to fix first.
If your mail app did not open, here is the address: hello@infiniteloop.tech
Have a similar problem?
Write to us about what is going on. We reply within 2 business days.
More case studies
- Content Idempotent model calls: no repeat paid for, no call lost
- Subscriptions Paid content for paid subscriptions only
- Platform A common base for new services
- Reliability Multi-step operations across services
- Data Test databases without personal data
- Content delivery New content without a release: downloaded whole, read offline