03 of 14
AI & Computer Vision
Smart Parking System
A camera-driven parking system handling 100,000+ vehicles across a 6-story garage, 75 cameras. Zero double-bookings since launch. That came from a database constraint replacing the concurrency check that used to sit in application code.
- Built at
- DevTechGuru
- Scale
- One 6-story garage, 75 cameras.
- Category
- AI & Computer Vision

- Booking Errors
- 0
- Vehicles tracked
- 100,000+
Context
Plates were written down by hand at the gate. Queues formed behind whoever was doing the writing, and revenue leaked out through the gap.
Challenge
A car doesn't wait. The gate has to read a plate, match it to a card, price it against the tariff table and open — while the same database is taking a reservation for the bay that car is heading to.
Non-negotiables
- No double-bookings
- Video and database always consistent
- Every payment accounted for
Calls I made
- 01
Constraint, not a code path
The check used to live in application code. It could never have worked there: two SELECTs both see a free bay before either INSERT lands. The reservation table now carries a partial unique index, and the losing booking fails at insert.
- 02
Hardware adapter layer
Camera vendors sit behind one adapter interface. Swapping a vendor is a config change; the 75 units in the garage look identical to everything above the adapter.
The decision, in code
The migration that ended the double-sell
# Two drivers hit /reserve within the same millisecond. Both SELECTs saw
# the bay as free, both INSERTs succeeded, and the garage sold one bay twice.
#
# The application-layer check could never fix this: between the read and the
# write there is a window, and no amount of Python closes it. The database
# already had the primitive.
class Migration(migrations.Migration):
operations = [
migrations.AddConstraint(
model_name="reservation",
constraint=models.UniqueConstraint(
fields=["bay", "slot_start"],
condition=Q(status__in=["held", "active"]),
name="uniq_active_reservation_per_bay",
),
),
]
def reserve(bay, slot_start, driver):
try:
return Reservation.objects.create(
bay=bay, slot_start=slot_start, driver=driver, status="held",
)
except IntegrityError:
# Losing the race is a normal outcome, not an error condition.
# The second driver is offered the next free bay instead.
raise BayTaken(bay)The partial index is the load-bearing part: the constraint applies only to held and active rows, which is what lets a bay be reserved again once a previous reservation is released or expires. Drop that condition and you don't get a race — you get a garage where every bay is single-use forever.
Trade-offs accepted
- Under load the system refuses a booking instead of risking a conflict. That costs throughput at peak hour, when the garage is full and the refusals are most frequent.


Outcome
100,000+ vehicles since launch. Zero double-bookings recorded.
When software drives something physical, partial correctness isn't enough. A wrong answer ends up on the ground.
Stack
- Python
- Django
- TypeScript
- React
- Tailwind CSS
- PostgreSQL
- Docker
- GitHub Actions for CI/CD
- Linux VPS
- Celery
Got something similar in mind?
Send 3 lines. I reply within a day.