Skip to content

Messaging: recap and quiz

  1. Queues and pub/sub. A queue lets the producer hand work over without waiting: a work queue gives each message to one consumer and pub/sub gives it to every subscriber, and the backlog grows by the producer rate minus the consumers’ combined rate.
  2. Backpressure. A bounded queue refuses what it cannot hold, which moves the overload to the producers, who must wait, drop or send fewer.
  3. Retries and dead letters. An unacknowledged message returns after the visibility timeout, and a limit on attempts plus a dead-letter queue keep a poison message from circulating for ever.
  4. Delivery semantics. When the acknowledgement happens chooses between a lost message and a repeated one, and at-least-once with a consumer that copes gives an effectively-once result.
  5. Partitions and consumer groups. A log broker keeps order inside a partition, and a group reads each partition with one consumer, so partitions cap the parallelism and a hot key makes one lane long.
  6. Offsets and replay. The group’s committed offset is where a new owner starts, so a crash repeats the work since the last commit.
Idea What breaks What you see What helps
Queue Producers outpace consumers A backlog that only grows, and a longer wait More consumers than the rate needs, or fewer messages
Backpressure A full queue refuses, and the producer ignores it Lost or repeated messages upstream Make the producer wait, shed or slow, deliberately
Retries A message that never works Capacity spent on the same message A limit on attempts and a dead-letter queue someone watches
Delivery The acknowledgement is lost, or comes first Repeated work, or lost work Acknowledge after the work and make the handler safe to repeat
Partitions Too few partitions, or one hot key Idle consumers, one partition far behind More partitions, a better key, a split hot key
Offsets A crash between two commits The same messages processed again A shorter commit interval, a consumer safe to repeat

Each question points back to the lesson that answers it.

  1. Does the work need to be done before you answer? If not, a queue lets you answer first and do it later. (Queues and pub/sub)
  2. Should one worker or every reader get each message? Work queue, or publish/subscribe. (Queues and pub/sub)
  3. Is the consumers’ combined rate above the producers’ average? If not, the backlog grows without end. (Queues and pub/sub)
  4. What happens when the queue is full? Choose the limit and what the producer does with a refusal. (Backpressure)
  5. How many attempts, how long between them, and who looks at the dead letters? (Retries and dead letters)
  6. When do you acknowledge, and is the handler safe to run twice? (Delivery semantics)
  7. How do you publish an event and save a row without losing one? Write both in one transaction and publish from an outbox. (Delivery semantics)
  8. What must stay in order, and what is its key? Order only holds inside a partition. (Partitions and consumer groups)
  9. How many partitions will the busiest group need, and which key could be hot? (Partitions and consumer groups)
  10. How often do you commit, and what is a repeat worth? (Offsets and replay)

Nine questions cover the whole module. Every option is explained, whether it is right or wrong.

Messaging: module quiz

This quiz needs JavaScript to check your answers.

Question 1 of 9

Producers send 40 messages a second to a work queue. 5 consumers each take 6 messages a second. The queue starts empty.

How many messages are waiting after 60 seconds?

Enter a number and choose its unit.

messages
Question 2 of 9

A bounded queue is full. Producers keep sending 30 messages a second and the consumers take 20 a second.

What does the queue accept, and what does it refuse?

Choose one answer.

Question 3 of 9

One message in a queue fails every time a consumer tries it. The queue puts a failed message back after the visibility timeout, with no limit on attempts.

What happens, and what is the usual remedy?

Choose one answer.

Question 4 of 9

A poison message is received at time 0. The visibility timeout is 5 seconds and a message may be received 3 times before it goes to the dead-letter queue. Each retry comes as soon as the message is visible again.

After how many seconds is it moved to the dead-letter queue?

Enter a number and choose its unit.

seconds
Question 5 of 9

A topic has 4 partitions. A producer sends the events of customer 7 with the key customer-7, and the events of customer 8 with the key customer-8.

Which order is guaranteed to a consumer?

Choose one answer.

Question 6 of 9

A topic has 6 partitions and a consumer group has 10 consumers.

How many consumers have no partition to read?

Enter a number and choose its unit.

consumers
Question 7 of 9

One partition of a 4-partition topic receives most of the messages, because most of them carry the same key. Its consumer falls behind. The group has 4 consumers.

Does adding 4 more consumers to the group fix it?

Choose one answer.

Question 8 of 9

A group of consumers commits its offsets every 10 seconds. One consumer crashes.

What does the next owner of its partitions do, and how can you reduce the repeated work?

Choose one answer.

Question 9 of 9

A team wants each payment handled once. Their broker delivers at least once.

Which design gets the effect they want?

Choose one answer.

A broker moves messages, and something has to process them. The next modules look at stream and batch processing, which read these logs and queues to compute over time, and at idempotency, which is how a consumer or an API survives the repeats that this module said cannot be avoided. Ask this module’s questions first when you meet them: who gets each message, what happens when a consumer is slow or dead, and what a repeat costs.

Your progress

Built by GhaziAlibi.

© ShardCraft. All rights reserved.