Matthew Kong

Case studies/Yelp, 2015 to 2016

Request-A-Quote routing and merchant notifications

A transactional outbox and idempotent delivery so one consumer lead reaches several merchants exactly once.

Two monitors of code in a dark room lit from below
  1. Client
  2. Quote API
  3. MySQL transaction
  4. Outbox
  5. Worker queue
  6. Email and push gateway
  7. Merchant inbox

Why this work, at that time

Yelp introduced Request-A-Quote in 2016 and submissions grew quickly through the year, which made lead routing and merchant response workflows the problem worth solving.

The problem

One consumer lead could route to several merchants. Messages could time out or retry, but a merchant inbox must never show the same lead twice and the consumer must always see a durable status.

The team and my part

Six engineers: three backend, one merchant web, one consumer and mobile, one platform partner, with PM, QA and merchant operations shared. I designed the quote request transaction and the notification worker.

Data and index design

quote_request(id, consumer_id, category, state, created_at); quote_recipient(request_id, merchant_id, delivery_state); outbox(id, aggregate_id, type, created_at); delivery_attempt(id, recipient, attempt, outcome). Unique on (request_id, merchant_id).

API and event contract

POST /v1/quote-requests with an Idempotency-Key header; GET /v1/quote-requests/{id}. Internal event quote.created {id, category, recipient_ids}. States: CREATED, ROUTED, PARTIALLY_DELIVERED, RESPONDED.

Core logic

Create the request and its recipients in one database transaction and write the outbox record in the same commit, then process asynchronously. The delivery worker dedupes on request, merchant and event type, retries with capped exponential backoff and dead-letters poison events.

Implementation sequence

  1. Define eligibility rules and immutable request ids; write the provider-failure matrix with the PM.
  2. Create normalized MySQL tables and unique constraints; add a request-level idempotency store.
  3. Commit the request and outbox atomically; add a polling or change-capture publication worker.
  4. Implement the merchant notification adapter and independent delivery status updates.
  5. Run duplicate-post, crash-after-commit, replay and provider-throttle tests; launch by service category.

Environments and release

Python service and queue workers; an integration environment with stubbed email and push providers; production rollout by service category with a dashboard for delivery lag and dead letters.

Failure drill

A worker crashes after sending but before acknowledging, so the message is resent. Email is at-least-once, but the recipient record is idempotent, so the inbox shows one lead.

Scale and targets

Modeled scale

  • 2K requests per day, about three merchants each
  • About 6K delivery attempts per day with bursts
  • 25K eligible merchants in the rollout

Acceptance targets

  • User-visible delivery status p95 within 15 seconds
  • No duplicate inbox lead records
  • Dead-letter replay within 30 minutes

Scale figures are the sizing model behind the design. Targets are acceptance criteria, not measured results.

The trade-off I would defend

Never call three message providers synchronously inside the customer's HTTP request. A durable outbox trades instantaneous notification for correctness.