1. Why queues exist
- Decoupling availability levels in multiple services
- Absorbing bursts traffic
- Moving work off the request path.
- It’s not about scalability:
- It’s about how fast workers pick the jobs.
- Otherwise, a queue only determines how long tasks are not done.
2. The cost of asynchronous:
- Eventually consistency: long time to receive email
- At-least-once delivery: the consumer must be idempotent.
- A new monitoring surface: consumer lag, dead letter queue depth, worker health, redelivery rate
- Harder debugging: need correlation IDs and distributed tracing to follow the request
- Not a sync function: A → B → C → D in same function.
- Async function (tracing): required tracing in multiple system + Kafka
- Ordering problem: a constraint of design, rather than a given.
3. Producer, Consumers and Acknowledges
4. Delivery Semantics
- At-most-once: no retry, never duplicates → problem: miss message.
- Solution: outbox patterns + PID and sequence number
- At-least-once: retry, duplicated → problem: duplicate
- Solution: consumer idempotency
- Exactly-one: might be impossible in Kafka (*)
- Producer: “the message never arrived in Kafka”
- Be aware in one of 2 cases:
- The message never arrived in Kafka.
- The message arrived, but the ack was lost.
- If producer:
- choose to retry → duplicate
- Do not retry → loss.
- Solution:
- Producer: Have PID + sequence number to the message.
- Retry but idempotence.
- We cannot define it correctly in Kafka
# Producer
enable.idempotence=true
transactional.id=my-processor-1
acks=all
# Consumer
isolation.level=read_committed
5. Visibility Timeout (SQS has)
- When a consumer picks up a message → this message become invisibility for other consumers for a period.