Django vs FastAPI for a tenant reservation workflow
For an existing Django system, its ORM and transaction APIs can keep reservation logic near the data model. For an API service already organized around Pydantic contracts and an independently owned repository, FastAPI keeps HTTP boundaries explicit. Neither choice removes tenant authorization, uniqueness, stock invariants, durable notification, or rollout work.
Django 5.2 LTS (5.2.18 package pin) versus FastAPI 0.162.0. Same database schema, stock, tenant, idempotency and notification requirements in both cases. Framework contracts are distinct from synthetic SQLite proof; no speed or throughput result is claimed.
Django supplies an ORM and migration framework plus request handling; FastAPI supplies HTTP contract/dependency machinery while persistence choices remain application-owned. Both can implement the same tenant reservation contract only when their application and database boundaries are explicit.
Compare the practical consequences
Scroll sideways to compare all columns on a smaller screen.
Django and FastAPI by decision criterion
Criterion
Django
FastAPI
What changes the decision
Request contract
Django forms, serializers or explicit view parsing are application choices; ORM model validation is not automatic on save.
FastAPI/Pydantic validates declared request and response schemas at the HTTP boundary.
Both need tenant authorization after parsing; valid shape is not permission.
Persistence owner
Django includes an ORM and migration system; model/query/transaction policy still belongs to the application.
FastAPI does not choose the ORM, schema migration or transaction owner.
Keep the exact same DB, schema, constraints and isolation requirements in either design.
Tenant scope
Scoped managers/querysets and authorization policy are application-owned; retrieve through a tenant-filtered queryset.
Dependency can provide principal, but repository query must explicitly scope by that principal.
Framework mechanics differ; data isolation obligation is equal.
Reservation atomicity
transaction.atomic() and ORM updates support a transaction boundary; backend semantics govern locks.
Route/service calls the selected persistence transaction implementation.
Neither framework creates atomicity between database commit and external notification.
Idempotency
A tenant/key UniqueConstraint and conditional stock update can enforce replay and inventory invariants.
Same database constraints and conditional update remain required.
The fixed DB invariant decides outcome; framework choice does not.
Notifications
on_commit() prevents pre-commit publication, but is not durable delivery; add an outbox.
BackgroundTasks are in-process best-effort; use same transactional outbox.
Notification failure after commit must be visible as committed-but-not-notified.
Async boundaries
Django 5.2 async ORM support has transaction limits; bridge a complete sync transactional unit.
Sync routes/dependencies use a threadpool; async handlers must not call blocking libraries directly.
Workload/library compatibility and cancellation are operational choices, not speed guarantees.
Tenant T-7 begins with stock 3 for SKU-9. Its member submits quantity 2 under R-1. The first accepted request creates one reservation and leaves stock 1; replaying identical R-1 returns that reservation; reusing R-1 with a different payload conflicts. T-8 access changes nothing. Competing R-2 for quantity 2 sees only 1 and is rejected, leaving stock 1. A later notification failure leaves the reservation committed and delivery pending.
The existing stock row starts at 3. The first accepted T-7 request reserves 2 and leaves that row at 1. Identical R-1 replay returns the same stored result without decrementing again; the same key with a different payload conflicts. T-8 access changes no row. Competing R-2 quantity 2 affects zero stock rows, creates no reservation or outbox event, and leaves stock at 1.
Claim the (tenant, idempotency_key) row with a payload hash and pending status before mutating stock, in the same transaction. If the conditional decrement succeeds, insert reservation and outbox rows and store the accepted result. If it affects zero rows, store a stable insufficient-stock result for R-2 and commit the claim, so retrying R-2 returns the same rejection. The notification worker retries outbox delivery under a stable event ID.
Django view/form or FastAPI request schema parses fields; each route must then derive tenant identity from the authenticated principal and scope the repository lookup.
Django request parsing does not authorize a model instance. FastAPI validation does not authorize a valid tenant_id. In both, never accept client tenant identity as authority.
Test absent, malformed, foreign tenant and authorized requests with the same ID shapes. Keep response disclosure policy explicit.
What protects stock and idempotency under competing requests?
Both need the same database invariant: unique (tenant_id, idempotency_key), a payload hash and stored outcome, a nonnegative stock constraint, and a conditional decrement. Claim the unique key before stock mutation in one transaction. On a uniqueness conflict, recover the transaction and read the existing payload/status: same payload returns its stored outcome; a different payload conflicts. Django exposes ORM transaction primitives; FastAPI delegates them to the selected persistence layer.
For T-7/SKU-9, the transaction first claims R-1 with its payload hash. Only then run UPDATE stock SET available=available-2 WHERE tenant_id=T-7 AND sku=SKU-9 AND available>=2; exactly one affected row permits reservation/outbox insert and an accepted stored result. Zero rows stores an insufficient-stock result for that key and leaves stock unchanged. A concurrent duplicate that loses the unique claim must roll back to a savepoint/transaction, reread after recovery, compare payload hashes, and return the winner’s stored outcome without decrementing.
After R-1 leaves stock 1, R-2 quantity 2 affects zero rows and commits a stable rejection; stock remains 1. If the transaction itself rolls back before commit, the original stock row remains at 3 and no idempotency claim, reservation, or outbox row exists. PostgreSQL lock/isolation behavior needs PostgreSQL integration proof. Django select_for_update() docs describe its API on supported backends; synthetic SQLite examples do not verify it.
What state exists after commit but notification failure?
Reservation is committed; notification is pending or failed. A Django on_commit callback and a FastAPI BackgroundTask are not durable queues.
In Django, transaction.on_commit() can wake a publisher after the reservation transaction commits, but callback execution is not durable. FastAPI BackgroundTasks run in the web process after response creation and can disappear if that process stops.
The atomic record is reservation + outbox event, not reservation + email. If sending fails after commit, report reservation accepted and delivery pending/failed; retry the outbox event using a stable event ID. Never ask the client to create a fresh reservation as a notification retry.
What happens for the stated T-7 reservation trace?
State transitions are deterministic: existing stock 3 -> 1 on first T-7/R-1; identical replay returns the saved result and stock stays 1; changed payload under R-1 conflicts; T-8 access changes no row; R-2 quantity 2 is stored as insufficient stock and changes no stock/reservation/outbox row; notification failure after commit leaves R-1 accepted with delivery pending.
The idempotency claim (tenant, key, payload hash, status/result) is inserted before inventory mutation in the same transaction. The conditional stock update, reservation and outbox event commit together. The R-2 zero-row path stores a stable rejection against its key; retrying it does not silently become a new success after stock changes.
If R-1 transaction rolls back before commit, the stock row remains at 3 and its idempotency claim, reservation and outbox insert all roll back. If the client loses the success response after commit, replaying R-1 reads the stored accepted result. A notification retry acts on the outbox event only, never by creating another reservation.
Fixed workload state trace · Worked example
Initial: stock(T-7, SKU-9)=3; no R-1/R-2 idempotency, reservation, or outbox rows.
T-7/R-1 qty=2: claim key+payload, decrement stock to 1, insert reservation and outbox, commit accepted result.
Replay same R-1 payload: return stored accepted result; stock remains 1.
Replay R-1 with changed payload: return conflict; no mutation.
T-8/R-1: tenant-scoped lookup finds no claim; no T-7 row changes.
T-7/R-2 qty=2: claim key, conditional decrement affects 0 rows, persist insufficient-stock outcome; stock=1, no reservation/outbox for R-2.
Rollback before commit: existing stock remains 3; no claim, reservation, or outbox row survives.
Post-commit notification failure: reservation stays accepted; outbox delivery remains pending for retry.
This worked trace applies the fixed initial state and request sequence above. It names intended application/database outcomes and is not executable proof, a concurrency result, or a performance measurement.
Fixed T-7/T-8/R-1/R-2 workload trace; conceptual state transitions, not an executed transaction, concurrency proof, or performance measurement.
Keep a stable HTTP contract and database ownership boundary, pilot a bounded workflow, and define rollback before routing more traffic.
Schema rollout uses compatible expand/backfill/contract steps, whichever framework owns migration files. Drain old workers before destructive contraction.
A framework swap does not erase ORM mapping, authentication, retry, observability, or on-call costs. Compare them with the team’s actual skills and existing system.
The published Django executable body establishes the ORM’s tenant-filtered query result and tenant-scoped uniqueness constraint on synthetic in-memory SQLite, after its authorized execution receipt exists. It says nothing about PostgreSQL row locks.
Django executable bodies exercise an in-memory SQLite schema: tenant-filtered ORM query, uniqueness, nested savepoint rollback and on_commit timing. They do not test two concurrent transactions, select_for_update(), PostgreSQL isolation, or external delivery.
FastAPI bodies use the pinned local TestClient to check validation, response filtering, override-driven authorization denial and a yield finalizer. They do not test a real identity provider, DB session, socket disconnect, or production ASGI server. These are four bounded framework/API assertions, not an end-to-end workload or load test.
Choose from current ownership and measured workload constraints, not a framework speed stereotype. Django may reduce persistence/migration choices for a team already operating Django; FastAPI may fit teams wanting explicit API schemas and independently selected storage.
Pilot with the same acceptance contract, failure cases, observability, and deployment overlap. Include migrations and on-call in reversal cost.
No throughput claim is measured here. Benchmark only if a demonstrated workload bottleneck makes it a real decision criterion.
These are Hacker News job posts that mention these technologies, not employee earnings or a measure of what a skill adds to pay. The amounts summarize annualized advertised minimums in approximate USD. Groups can overlap and differ in roles, locations and dates.
Approximate USD using ECB daily reference rates as of 2026-10-30. Original currencies and offer ranges remain on the source listings. These figures cover posts tagged Django, rather than every job in the broader technology family.
Approximate USD using ECB daily reference rates as of 2026-10-30. Original currencies and offer ranges remain on the source listings. These figures cover posts tagged FastAPI, rather than every job in the broader technology family.
Middle-half salary ranges on one shared scale
The band runs from the 25th to 75th percentile; the vertical marker is the median. Both rows use approximate USD per year.
Django $130,000 median
FastAPI $150,000 median
$93,792$160,000
How many source posts appear in both salary groups?
Source posts can appear in both groups in this salary dataset. The same advertised salary can therefore contribute to both summaries.
Django posts in this dataset4 of 52 also tagged FastAPI · 7.7%
FastAPI posts in this dataset4 of 55 also tagged Django · 7.3%
What these bars count
Bars count distinct source posts with known HN IDs in these salary cohorts, not every Hacker News post or the wider job market. Duplicate IDs count once; rows without a valid HN ID are left out, so the bars cannot establish overlap for the full population. These are source-post counts, not the salary-observation counts in the cards above. A missing tag does not prove a technology was not used. Overlap does not establish employer preference, adoption or a pay effect.