Card 08/ 09

ExerciseDifficulty: Intermediate1 min

Practice: Queue or Topic for Four Flows

Thumbnail jobs, price changes, password-reset emails and audit events.

Choosing between a queue and a publish/subscribe topic is practised here on four flows from one online shop. For each, decide queue or topic and who reads it, and name any risk of a duplicate, before opening the answers.

The brief.

  1. Sellers upload product photos; six workers make thumbnails.
  2. A product's price changes; search, the page cache and analytics must all update.
  3. A user asks for a password reset; one email must be sent.
  4. Every admin action must be written to the audit log and also checked by the fraud service.
Check your answers
  1. A queue, shared by the six workers, so each photo is resized once. A duplicate costs one wasted resize, which is harmless.
  2. A topic, with search, the cache and analytics each subscribed, ideally each through its own queue. A duplicate update is harmless when it sets the same price.
  3. A queue, read by the email service. A duplicate sends two reset emails, so record each request id and skip one already sent.
  4. A topic, with the audit log and the fraud service each subscribed. The audit log should ignore an action id it has already written, or the record shows the action twice.