API performance Level 2 This level · 13 of 20
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.

Could you say this in an interview?

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 Acceptedrfc-editor.org
  2. Apache Kafka introkafka.apache.org
Previous
Next