A production-ready REST API for a carpooling platform. Drivers publish trips, passengers book seats, and both parties track each other in real time via WebSockets.
Auth and permissions
Authentication uses JWT with short-lived access tokens and rotating refresh tokens. Permissions use a granular RBAC system — drivers and passengers have different access to the same resources depending on the current trip state.

For example, a driver can cancel a trip in pending state but not once
it is in_progress. A passenger can see driver location only after
their booking is confirmed. These rules are encoded as DRF permission
classes rather than scattered view-level conditionals.
Async task flow
Celery handles everything that should not block the request cycle: booking confirmation emails, cancellation window enforcement, and post-trip review prompts triggered by trip completion.

Celery Beat runs a periodic task that expires unpaid bookings after 15 minutes — no cron job needed, and the state machine never gets stuck in a limbo state.
Real-time tracking
Drivers share location via a WebSocket connection. Passengers with a confirmed booking on that trip receive position updates without polling. The channel is closed automatically when the trip reaches a terminal state.
Caching
Redis caches frequently-read trip listings with a short TTL. Cache invalidation happens explicitly on trip state transitions rather than relying on expiry alone.
Testing
Full Pytest suite with factory_boy for fixtures and unittest.mock
for external services. Every permission rule has a corresponding test
for both the allowed and denied case.
Stack notes
# Permission class — trip state is part of the access decision
class IsTripParticipantWithActiveTrip(BasePermission):
def has_object_permission(self, request, view, obj: Trip) -> bool:
if obj.status not in ("confirmed", "in_progress"):
return False
return (
request.user == obj.driver
or obj.bookings.filter(
passenger=request.user,
status="confirmed",
).exists()
)