Medium java backend

Move slow work to a background queue

The 30 second answer

If work like sending emails, generating reports or calling slow partners does not need to finish before the response, I put it on a queue and process it in the background. The API answers fast, often with 202 Accepted and a status link. Background work must be idempotent and retried safely, and the client needs a way to see when it is done.

Return 202 Accepted and do the work asynchronously (emails, reports, indexing). RFC 9110 defines 202 for exactly this case: accepted, not yet done. Kafka or a job queue holds the work.


Sources (2)
  1. RFC 9110 ยง15.3.3 202 Accepted
  2. Apache Kafka intro