docs: add readme architecture diagrams
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Backend README
|
||||
# Backend
|
||||
|
||||
This backend is a minimal production-aware PostgreSQL job queue implemented with Django and Django REST Framework.
|
||||
|
||||
@@ -23,6 +23,8 @@ All queue behavior is implemented in service functions under `jobs/services.py`.
|
||||
|
||||
## High-Level Architecture
|
||||
|
||||

|
||||
|
||||
```text
|
||||
PostgreSQL
|
||||
|
|
||||
@@ -91,6 +93,8 @@ This is an at-least-once queue. A worker can perform a side effect and then cras
|
||||
|
||||
### Statuses
|
||||
|
||||

|
||||
|
||||
`Job.status` is intentionally small:
|
||||
|
||||
```text
|
||||
@@ -114,6 +118,8 @@ Unsupported transitions are rejected by service-level ownership checks and by da
|
||||
|
||||
### Ownership
|
||||
|
||||

|
||||
|
||||
A worker owns a job only when all of these are true:
|
||||
|
||||
```text
|
||||
@@ -143,6 +149,8 @@ This is one of the most important correctness properties in the project.
|
||||
|
||||
## Database Model
|
||||
|
||||

|
||||
|
||||
### `Job`
|
||||
|
||||
`Job` is the source of truth for queue state.
|
||||
@@ -240,6 +248,8 @@ This allows many jobs with no idempotency key while preventing duplicate client-
|
||||
|
||||
## Indexes
|
||||
|
||||

|
||||
|
||||
### Claim Index
|
||||
|
||||
```text
|
||||
@@ -405,6 +415,8 @@ Table jobs_jobevent {
|
||||
|
||||
## Claiming Algorithm
|
||||
|
||||

|
||||
|
||||
The worker claims a job in a short transaction:
|
||||
|
||||
```python
|
||||
@@ -471,6 +483,8 @@ Then a `succeeded` event is inserted.
|
||||
|
||||
## Failure And Retry Algorithm
|
||||
|
||||

|
||||
|
||||
On handler failure, the worker calls `fail_job`.
|
||||
|
||||
If attempts remain:
|
||||
@@ -515,6 +529,8 @@ max delay -> 300 seconds
|
||||
|
||||
## Lease Renewal
|
||||
|
||||

|
||||
|
||||
Long-running handlers can renew their lease:
|
||||
|
||||
```python
|
||||
@@ -540,6 +556,8 @@ The demo `demo.timeout` handler intentionally does not renew leases so the UI ca
|
||||
|
||||
## Expired Lease Cleanup
|
||||
|
||||

|
||||
|
||||
Every worker thread periodically runs cleanup:
|
||||
|
||||
```text
|
||||
@@ -570,6 +588,8 @@ There is no separate cron process. This is intentional for the interview version
|
||||
|
||||
## Worker Runtime
|
||||
|
||||

|
||||
|
||||
Run workers with:
|
||||
|
||||
```powershell
|
||||
@@ -643,6 +663,8 @@ Example:
|
||||
|
||||
## API
|
||||
|
||||

|
||||
|
||||
Base URL in local development:
|
||||
|
||||
```text
|
||||
@@ -1094,4 +1116,3 @@ POST /api/jobs/{id}/retry/
|
||||
GET /api/schema/
|
||||
GET /api/docs/
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user