Skip to content
tezvyn:

How would you architect personalized email and coupon delivery at scale?

Source: advertstar.netMediumHow cards are made

How would you architect personalized email and coupon delivery at scale?

This tests decoupled rendering and atomic coupon reservation. A strong answer uses template rendering, atomic coupon reservation, an idempotent queue, and batched ESP delivery. Red flag: generating coupons during SMTP without reservation risks overspend.

What's really being asked

The interviewer wants to see if you understand how to decouple dynamic content generation from high-volume delivery. Specifically, they care about idempotency, atomic inventory reservation, and graceful degradation under load. Generating unique single-use coupons introduces a scarce resource problem: if you retry a failed send or duplicate a job, you burn valid codes and anger finance. They also want to know you have handled real-world email constraints like ESP rate limits, bounce handling, and template rendering latency.

The full answer

A good answer hits four things in order. First, a template service that ingests user profiles and renders HTML or text greetings using a sandboxed engine, caching static partials to reduce compute. Second, a coupon microservice with an atomic reserve-and-mark flow, using a database row lock or compare-and-swap operation so each code moves from AVAILABLE to ISSUED exactly once, storing the mapping between user ID and code before any send attempt. Third, an idempotent job queue where each message has a deterministic ID derived from the campaign and user, allowing at-least-once retries without re-reserving a new coupon on every attempt. Fourth, a delivery layer that streams batches to the ESP, enforces per-domain rate limits, handles 4xx and 5xx responses, and consumes feedback loops for bounces and complaints.

The mistakes people make

Common wrong answers include generating the coupon inside the SMTP send call, which risks burning codes on network timeouts; storing coupons as plain text in the template database instead of a separate secured service; ignoring idempotency and allowing duplicate emails with different codes; and failing to mention rate limiting or warm-up schedules, which destroys deliverability. Another red flag is suggesting a single monolithic cron job that generates all emails synchronously, creating a single point of failure and memory bottleneck.

What usually comes next

Interviewers often ask how you would handle a partial outage where the ESP is down but coupons are already reserved; the correct pattern is to park jobs in a dead-letter queue and preserve the reserved codes rather than invalidating them. They may also ask about personalization beyond the greeting, such as product recommendations, which tests whether your template engine can accept arbitrary data schemas. Another follow-up is compliance: how do you honor unsubscribe requests instantly when a batch is already queued, which requires a pre-send eligibility check against a suppressed-user set.

A concrete example

Imagine a flash sale for one million users. Your campaign service partitions the audience into chunks of ten thousand. For each chunk, it calls the coupon service to bulk-reserve codes, writing user-code pairs into a pending-sends table with a campaign-scoped UUID. A worker pool picks up these records, renders templates with the reserved greeting and code, and enqueues delivery jobs with deterministic IDs. If an ESP webhook reports a hard bounce, you remove the address from the chunk and log the reserved code as unclaimed for reuse or write-off. If a worker crashes mid-batch, the deterministic job ID prevents re-rendering and re-sending when the job retries.

Interview question

Which pattern prevents duplicate coupon reservations when high-volume email jobs are retried due to ESP timeouts?

  • a.Roll back reserved coupons to AVAILABLE after each timeout and reserve a new code on retry
  • b.Store coupons as plain text inside the template database for the rendering engine to inject
  • c.Generate the coupon inside the SMTP call so it is only created when the ESP accepts the message
  • d.Atomically reserve the coupon before enqueueing and deduplicate retries with deterministic job IDsCorrect
Why?

Atomic reservation before enqueueing coupled with deterministic job IDs ensures exactly one code is mapped per user even during at-least-once retries. Generating coupons during SMTP seems safe but burns inventory on network timeouts without guaranteed delivery.

Just read this? Test yourself on what you have been reading.

Read the original → advertstar.net

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles