SDE & MLE Prep

Long-Running Tasks

When: work that takes seconds to hours — video transcoding, report generation, ML training, bulk imports, sending a million emails.

client --POST /jobs--> API --enqueue--> queue (SQS / Kafka / Redis) --> worker pool --> result store (S3/DB)
   |       202 Accepted + job_id                                      | heartbeat, progress %
   +--GET /jobs/{id} (poll) or webhook / WebSocket push when done <---+
  • Return 202 + job id immediately; never hold an HTTP request open for minutes.
  • Workers take a lease (visibility timeout) and heartbeat; if they die the job reappears. Make jobs idempotent (or checkpoint progress) because at-least-once delivery means repeats.
  • Retries with exponential back-off, then a dead-letter queue for inspection.
  • Split huge jobs into chunks (fan-out / fan-in) so they parallelize and partial failures retry cheaply.
  • Separate queues/priorities per job type or tenant so one heavy customer can't starve others; autoscale workers on queue depth.