Submitting: saved first, then handed on
The API stores the code in object storage, then writes the submission row and an outbox row in one transaction, and replies 202 with the id. A relay publishes the job to a durable judge queue, so a crash between saving and handing off cannot strand the submission, as in the transactional outbox (opens in a new tab) pattern.
- The page posts the code with a key it generated for this click.
- The API stores the code, then the submission row and an outbox row in one transaction.
- It replies 202 with the submission id, and the user sees “submitted”.
- A relay reads the outbox and publishes the job to the durable judge queue.
Diagram as text
Components: Submission row and outbox (SQL DB); Outbox relay (Worker); Browser (Client); Submissions API (API gateway); Judge queue (Queue); Judge workers (Worker); Code by key (Object store). Connections: Browser → Submissions API (POST, client key); Submissions API → Submission row and outbox (one transaction); Submissions API → Code by key (store the code); Outbox relay → Submission row and outbox (read the outbox); Outbox relay → Judge queue (publish the job); Judge workers → Judge queue (pull).
Read:Learn: Long-running tasksLearn: Producer-consumer / work queue
Check yourself
Why not write the row, then put the job on the queue, in two separate steps?
Show answerHide answer
A crash between them leaves a saved submission with no job, waiting for ever. Writing the job in the same transaction closes that gap.