Delivered remotely for a business based in Doha, Qatar. Names withheld by agreement.
Project Overview
Online grocery fulfillment operates under unforgiving physical constraints that standard parcel e-commerce never encounters. Fresh produce sells by variable weight, frozen goods cannot wait in ambient staging areas, and dozens of shoppers compete simultaneously for the same evening delivery windows across dense urban neighborhoods.
Engineered for hyperlocal quick-commerce operations in Doha, we built an end-to-end online grocery marketplace connecting Flutter consumer, picker, and rider applications to a modular NestJS backend and a PostgreSQL database extended with PostGIS. Every layer is purpose-built around dark-store inventory accuracy, cold-chain time windows, and real-time substitution workflows.
Hyperlocal Grocery Bottlenecks
Regional supermarket aggregators and rapid-delivery operators frequently hit structural breakdowns between digital carts and physical warehouse aisles:
- Phantom shelf inventory: Delayed ERP batch syncs allowed shoppers to purchase fresh dairy or bakery items already cleared from dark-store shelves.
- Peak-hour slot overbooking: Naive checkout validation permitted concurrent buyers to claim the final van capacity in a high-demand delivery window.
- Unresolved substitution friction: Phone calls from busy pickers stalled packing lines whenever shoppers missed unknown caller IDs.
- Catch-weight settlement errors: Fixed-amount card captures forced messy partial refunds or manual cash reconciliations whenever deli and produce weights varied from catalog estimates.
Architectural Strategy
We unified catchment geospatial routing, atomic slot/inventory locking, and real-time picker-to-shopper orchestration inside a cohesive NestJS service architecture. PostgreSQL with PostGIS serves as the authoritative ledger for store catchment polygons, aisle bin locations, multi-zone slot capacity, and financial settlements.
Redis sits directly in front of high-contention paths—holding transient checkout slot locks, ephemeral cart stock reservations, and live rider GPS coordinates—while NestJS WebSocket gateways connect Flutter picker tablets and consumer phones into an interactive fulfillment loop during active order assembly.
Core Capabilities
- Catchment-Aware Storefront & Catalog (Flutter): Resolves shopper GPS pins via PostGIS to show live neighborhood store stock, ambient/chilled/frozen tags, and bilingual RTL/LTR merchandising layouts.
- Dynamic Slot & Express Dispatch Engine: Balances scheduled multi-hour delivery windows alongside rapid express tiers, throttling slot availability automatically by picker queue depth and fleet capacity.
- Guided Dark-Store Picker App (Flutter): Sequences pick lists by store aisle and temperature zone (ambient first, chilled and frozen last) with barcode validation and Bluetooth scale capture.
- In-App Live Substitution Approvals: Pushes one-tap visual swap prompts to shoppers via WebSockets and push notifications when a shelf item fails quality inspection.
- Cold-Chain Rider Dispatch & Proof of Delivery: Bundles temperature-compatible orders into optimized multi-drop routes with OTP or photo handoff verification.
Technical Architecture
Shopper apps, picker devices, and rider clients connect over HTTPS and authenticated WebSocket channels into NestJS API gateways. Geospatial queries and transactional order commitments persist in PostgreSQL/PostGIS, while Redis coordinates distributed slot locks and live driver telemetry streams.
Flow: Flutter Consumer / Picker / Rider Apps → NestJS REST & WebSocket Gateways → Redis Slot Locks & Geo Streams → NestJS Domain Services (Catalog, Picking, Dispatch) → PostgreSQL & PostGIS Operational Ledger → Payment Pre-Auth & Push Gateways
Aisle-sequenced pick lists and temperature-staged packing ensure frozen goods spend minimal time outside refrigeration prior to courier handoff.
Technology Stack
| Category | Technology detail |
|---|---|
| Consumer & Field Apps | Flutter cross-platform iOS/Android apps for shoppers, dark-store pickers, and riders |
| Operations Portal | Web console for category merchandising, slot capacity tuning, and live dispatch |
| Service Backbone | NestJS TypeScript modular services handling catalogs, slots, picking, and settlements |
| Relational & Geo DB | PostgreSQL with PostGIS resolving catchment polygons, store stock, and order ledgers |
| Concurrency & Locks | Redis managing short-lived cart reservations, slot counters, and driver geo-streams |
| Real-Time Sync | NestJS WebSockets streaming live substitution prompts and courier GPS telemetry |
| Payment Pre-Auth | Gateway tokenization supporting authorization holds and final catch-weight capture |
| Push & Alerts | FCM and APNs delivering instant substitution approvals and doorstep arrival alerts |
Engineering Trade-offs & Solutions
| Engineering Challenge | Solution & Trade-off |
|---|---|
| Holding hard PostgreSQL locks during multi-minute shopper checkouts stalls concurrent carts | Used short-TTL Redis slot and SKU reservation keys backed by atomic PostgreSQL state transitions on payment pre-auth; trades strict long-held DB locks for responsive checkout concurrency. |
| Variable produce/butchery weights differ from catalog estimates | Implemented buffered payment authorization holds at checkout followed by exact final-weight capture once the picker weighs items; adds gateway state-machine complexity but eliminates cash/refund friction. |
| Freezer and basement dark-store aisles suffer intermittent Wi-Fi drops | Built offline-capable local SQLite pick queues inside the Flutter picker app that reconcile barcode scans upon reconnect, avoiding stalled warehouse shifts. |
| Polling rider locations over REST drains mobile batteries and saturates API pods | Streamed throttled adaptive GPS updates over persistent WebSocket channels backed by Redis Geo sets, scaling live map views smoothly. |
Security & Operational Reliability
Marketplace operations span consumer addresses, payment authorizations, and third-party supermarket partner payouts. NestJS enforces JWT-backed role separation isolating consumer profiles, store-scoped picker terminals, courier delivery tokens, and finance administrators.
Payment instruments tokenize directly with certified regional payment gateways so raw card details never traverse NestJS containers. Every inventory adjustment, damaged-stock write-off, and substitution approval writes an immutable audit trail in PostgreSQL for clear vendor reconciliation.
Performance & Peak-Hour Scale
Grocery demand clusters sharply around morning prep windows and pre-dinner evening hours. Caching neighborhood catalog trees and promotional banners per store in Redis keeps Flutter storefront scrolling fluid even during weekend rushes, while PostGIS spatial indexes (GIST) resolve delivery zones in single-digit milliseconds.
NestJS stateless service pods scale horizontally behind load balancers, and heavy background tasks—supplier ERP catalog syncs, daily vendor settlement PDFs, and abandoned slot sweeps—run on isolated worker queues so live checkouts never contend with batch jobs.
Operational Outcomes
Integrating shopper discovery, dark-store picking, and cold-chain delivery onto a single Flutter, NestJS, and PostgreSQL platform reshaped daily fulfillment execution:
- Accurate shelf-to-basket fulfillment: Aisle-guided picking and short-TTL reservations dramatically cut out-of-stock surprises after checkout.
- Streamlined substitution resolution: Real-time in-app prompts replace slow outbound support calls, keeping packing stations moving smoothly toward dispatch cutoffs.
- Balanced cold-chain integrity: Zone-aware pick sequencing keeps chilled and frozen items temperature-controlled until riders depart.
- Predictable peak slot management: Catchment-level capacity throttling protects courier SLAs during evening order surges without manual dispatch intervention.