Skip to content
All case studies
Student transportation platform8 min read

MURI: subscriptions, seats and trips for student transport

A subscription-based student transportation platform for Saudi Arabia: student and driver apps, an admin portal, and a Django/PostGIS backend. As team lead I set up the backend and its delivery pipeline and built its geography and trip-validation pieces; teammates built most of the platform features described here.

Software Team Lead · ASAS IT · 2025
Apps: student, driver, admin
3
Geography, SRID 4326
PostGIS
Driver wallet ledger
Double-entry
Bilingual end to end
AR / EN
The problem
Turn a paid subscription into real seats and trips, even when payment confirmation arrives late or more than once.
My role
Led the team; built the backend foundation, authentication, delivery pipeline, geography models and trip start/end validation. Teammates implemented payments, wallets, seat allocation and the client apps.
A key decision
Allocate seats inside a database transaction with row locks, and re-check payment status with the gateway before activating a subscription.
The result and its limits
The implementation covers subscriptions, payments, generated trips and driver wallets, with recovery for charged but inactive subscriptions. No usage or measured business-impact figures are published here.

The problem

What needed solving

Families subscribe students to daily transport on fixed routes. Behind that simple promise the operator has to sell seats without overselling vehicles, generate every trip for the subscription period, take card payments, track drivers, and pay them — across students, drivers and administrators.

Payments make it harder: a gateway confirmation can arrive late, twice, or not at all, and a paid subscription that never activates is worse than a failed payment.

Constraints

What the design had to respect

  • Seat allocation must be safe under concurrent purchases — never oversell a vehicle.
  • HyperPay notifications can be delayed or duplicated; activation must be idempotent.
  • Drivers work on mobile networks; trip actions must be validated against where and when they happen.
  • Arabic and English throughout, including app copy that changes without an app release.
  • A small team, so operational pieces had to stay simple.

Architecture

How the system fits together

A modular Django REST backend on PostgreSQL/PostGIS, with Celery and Redis for schedules and background work. Three clients share it: two Flutter apps and an Angular admin portal.

  1. Clients

    • Student app (Flutter)

      Subscribe and pay, follow the trip on a map, show a QR code at pickup.

    • Driver app (Flutter)

      Assigned trips, location uploads, QR pickup scans, SOS reports, wallet.

    • Admin portal (Angular 19)

      Users, geography, routes and trips, packages, payments, settings.

  2. Backend (Django/DRF)

    • Auth and user modules

      JWT with phone OTP; separate client, driver and administrator apps.

    • Subscriptions and trips

      Packages, seat allocation, trip generation, cancellations and change requests.

    • Payments and accounts

      HyperPay client and webhooks; double-entry ledger and driver wallets.

    • Regions, notifications, support

      PostGIS geography, Firebase push templates, server-driven translations.

  3. Async, data and infrastructure

    • Celery + beat

      Reminders, expiries, missed trips, payment reconciliation, route ordering, proximity pushes.

    • PostgreSQL + PostGIS

      Geography columns for cities, district polygons, stops and trip points.

    • HyperPay · FCM · S3

      Card and Apple Pay payments, push notifications, documents and media.

    • AWS delivery

      Docker Compose on EC2 in an Auto Scaling group; deploys bake a new machine image.

Engineering decisions

What was chosen, and why

  1. Allocate seats under row locks, in a fixed order

    Seat allocation runs in one transaction that locks the route's trip rows with SELECT … FOR UPDATE, always in the same (priority, id) order to reduce lock-order conflicts between concurrent purchases, then checks remaining seats per slot and fails cleanly when a route is full. Payment confirmation also locks the subscription and does nothing if it isn't awaiting payment, so a duplicate confirmation is harmless.

  2. Webhooks trigger work; the gateway decides

    HyperPay notifications are decrypted and authenticated (AES-256-GCM), logged, and handed to Celery. The task locks the transaction and re-fetches its status from HyperPay instead of trusting the payload; activation is dispatched only after the database transaction commits.

  3. Reconcile instead of hoping

    Three scheduled safety nets: re-poll transactions stuck in progress, re-drive subscriptions that were charged but never activated (up to five attempts, then alert an admin), and refund automatically when seats can't be allocated after payment.

  4. A ledger for driver money

    Driver earnings, commissions, bonuses and deductions are journal entries in a double-entry ledger that rejects unbalanced postings. Wallet holds change under row locks with F-expressions, and revenue can be recognised at payment or as trips complete.

  5. Validate trip actions by place and time

    Geography is stored as PostGIS geography (SRID 4326). A driver can start within 100 m of the route start or first active passenger stop, between 20 minutes early and 10 minutes late, and end within 100 m of the route end or last active passenger stop; QR pickups must happen within 50 m of the stop, in order.

  6. Server-driven app copy

    App strings live in a translation store on the backend and are served to both apps, so wording in Arabic and English can change without shipping new app builds.

Trade-offs

What those choices cost

Polling for live location

Simple infrastructure; drivers upload at most every 10 seconds and students poll every 10 seconds, so the map can lag by up to about 20 seconds.

Point-to-point distances in Python

Fine for checking one driver against one stop; a table-wide nearest-driver search would need spatial SQL instead.

Generate all trips at payment

Simple scheduling and reporting; changes go through cancellations and change requests.

Beat and Redis on the app instance

Simple at one instance; scaling out first requires moving the scheduler and cache to shared infrastructure.

Fixed-speed ETAs for stop ordering

Predictable and cheap (OR-Tools ordering for longer routes), but not traffic-aware.

Outcomes

What it delivered

End-to-end subscriptions

Choose a package, pay, get seats allocated, and receive generated trips for the whole period — with expiry and renewal reminders.

Driver operations

Geofenced trip start and end, QR pickups, absence marking, SOS reports with an admin workflow, and wallet withdrawals.

Payment recovery

Gateway re-checks and scheduled reconciliation recover delayed or missing confirmations. Allocation failures trigger a refund path; failures during refund handling require manual reconciliation.

Shipped apps

The student and driver apps are published on Google Play and the App Store.

My role

  • Led the team as Software Team Lead, and bootstrapped the backend: project structure, settings, logging, JWT and phone-OTP authentication, and the base permission classes.
  • Built the deployment pipeline: Docker Compose build, health check, machine-image bake and launch-template rollout.
  • Modelled geography with PostGIS (city centres and district polygons) and loaded the Saudi seed data.
  • Built the geofenced trip start/end validation and the server-driven translation store.
  • Teammates built the apps and admin portal, the Terraform, payments, the wallet ledger, notifications, route ordering, QR pickup, SOS and almost all of the tests; I describe those as team features.

Scope notes

  • No user counts, traffic figures or measured business outcomes are published here.
  • There are no WebSockets: live location is REST uploads plus polling.
  • The repository has several hundred tests, but CI runs deployments and a security scan, not the test suite.
DjangoDRFPostGISCeleryRedisHyperPayFirebaseFlutterAngular

Next case study

Maxpeak

The backend for a bilingual marketplace connecting Saudi companies with engineers from Egypt. I built the Django API, its authentication, and the automated first stage of a three-stage vetting flow: a Celery pipeline that extracts CV text and scores it with an LLM. The product is pre-launch.

Read it