Card 08/ 09
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.
- Sellers upload product photos; six workers make thumbnails.
- A product's price changes; search, the page cache and analytics must all update.
- A user asks for a password reset; one email must be sent.
- Every admin action must be written to the audit log and also checked by the fraud service.
Check your answers
- A queue, shared by the six workers, so each photo is resized once. A duplicate costs one wasted resize, which is harmless.
- 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.
- A queue, read by the email service. A duplicate sends two reset emails, so record each request id and skip one already sent.
- 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.
← → move through sections and cards