+--
[ /home ]
--
[ /works ]
--
[ github ]
--+
· · · · · · · · ·
Flowdiff viewer
Paste a .flowdiff file to draw it.
title SHOP-142: Send order confirmations from a queue, not during checkout ticket SHOP-142 https://example.com/browse/SHOP-142 pr shop-api#311 https://example.com/shop/shop-api/pull/311 pr email-worker#12 https://example.com/shop/email-worker/pull/12 repo shop-api https://example.com/shop/shop-api repo email-worker https://example.com/shop/email-worker > Checkout used to call the email provider itself, so a slow or failing > provider slowed or failed the checkout. Now the API saves the order and its > email job together, and a new worker sends the email from a queue. > > Merge email-worker#12 first. Until the worker runs, jobs wait in the queue > and no confirmations go out. > > The ticket also asks for an SMS receipt. Neither pull request adds one. participant web "Browser" "shop web app" participant api "Orders API" "Node service" participant db "Postgres" "orders DB" + participant queue "Queue" "jobs" > New in shop-api#311: a jobs queue between checkout and email, so > checkout no longer waits on the provider. + participant worker "Email worker" "new service" > New in email-worker#12: a process that takes jobs off the queue and > talks to the email provider. participant mail "Email provider" "HTTPS API" web -> api: HTTP POST /orders > Unchanged: the browser submits the cart. - api -> db: SQL INSERT order > Before: only the order was written. + api -> db: SQL BEGIN · INSERT order, outbox · COMMIT > shop-api#311 writes the order and an outbox row for its email in one > transaction, so neither can exist without the other. - api -> mail: HTTP POST /v3/send > Before: checkout called the provider and waited for it. A provider > outage made checkout fail. - mail --> api: 202 Accepted + api -> queue: publish order.confirmed\n{ orderId } > shop-api#311: after the commit, the API publishes the job and returns at > once. > > If the API crashes between the commit and the publish, the job is > never sent: nothing reads the outbox again yet. Worth a follow-up. api --> web: 201 Created > Same response as before, but it no longer waits on the email provider. + loop each job > email-worker#12. The worker handles one job at a time. + queue -> worker: deliver order.confirmed + worker -> db: SQL SELECT order, customer > Reads the order and customer straight from the orders database, so the > worker needs read access to it. + worker -> mail: HTTP POST /v3/send + alt 2xx + worker -> queue: ack + else error or timeout + worker -> queue: nack · retry with backoff > Retries five times, then drops the job. There is no dead-letter > queue, so a lost confirmation leaves no trace. + end + end
[ export jpg ]
· · · · · · · · ·