Practical System Design

Labs / Chapter 12

The notification task, created once

Match consume to produce and confirm a young backlog. Slow the handler until age climbs. Add consumers up to the partition count, then set the claim and commit-after toggles so a redelivered message_id creates one task and loses none.

The system

A redelivery arrives with the same message_id and the handler creates another confirmation task.

writeappenddeliver

API

40 msgs/s

Outbox

Same message_id on republish

Log

12 partitions

Workers

Consumers

2 assigned

process_order_event

  1. # produce/s = partitions = consumers = process_ms =
  2. def process_order_event(record, db, consumer):
  3. event = decode_and_validate(record.value)
  4. consumer.commit_next_offset(...)
  5. with db.transaction() as tx:
  6. first_delivery =
  7. if first_delivery:
  8. tx.create_notification_task(..., notification_type="order_confirmation")
  9. consumer.commit_next_offset(...)
  1. Backlog age0.0 s. Size 0 messages
  2. Assigned2 consumers on this topic
  3. This deliverySecond tasks 8/s. Lost tasks 0/s

Backlog age

Age is how late the oldest message is. Hold the oldest message under 2 seconds.

Age 0.0

The chart fills as the lab runs. s is the vertical unit.

  • Age
  • s