Every entrepreneur sketching an on-demand service app—home maintenance in Dubai, mobile mechanics in Texas, physiotherapy visits in London, or pet care in Sydney—starts with the booking screen. Yet the hardest engineering problems sit underneath: matching nearby supply without burning battery, preventing double-bookings under concurrent taps, enforcing strict job state transitions, and splitting payments cleanly when plans change.
Shipping an on-demand marketplace reliably means building a state-machine-driven backend first, then wrapping clean mobile apps around it.
Single App vs. Dual Apps: Choosing the Right Client Topology
Early founders often ask whether customers and service providers should live inside one mobile binary.
| Architecture Option | Pros | Cons | Best Fit |
|---|---|---|---|
| Two Apps (Customer + Provider) Sharing Packages | Lean permissions, focused UX, independent store release cycles, cleaner background GPS rules | Two App Store / Play Store listings to maintain | Cleaning, repair, beauty, roadside, tutoring, courier services |
| Single App with Role Toggle | One store submission and binary | Bloated permissions (customers asked for background location), complex navigation state | Peer-to-peer rentals where users frequently swap sides |
Even with two binaries in Flutter or React Native, keep shared API clients, DTO types, and design tokens in a single shared repository so validation rules never drift between customer and provider apps.
Geospatial Matching Without Destroying Provider Batteries
Querying every provider's latitude and longitude on every customer search does not scale, and polling provider GPS every two seconds drains phones by noon.
Adaptive Location Pings + Redis Geo & PostGIS
Split location handling into two tiers:
- Live Availability (
Redis GEOADD): Online providers send throttled location pings—every 30–60 seconds when idle, shifting to every 5–10 seconds only while actively en route to a job. Store ephemeral coordinates in Redis with a 5-minute TTL so offline providers automatically drop out of search results. - Service Territory & Scheduled Dispatch (
PostGIS): For scheduled services (plumbers, cleaners, mobile clinicians), query service polygons or travel radii directly in PostgreSQL usingGEOGRAPHYindexes:
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE TABLE provider_profiles (
user_id UUID PRIMARY KEY,
service_radius_meters INT NOT NULL DEFAULT 15000,
base_location GEOGRAPHY(Point, 4326) NOT NULL,
is_verified BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE INDEX idx_provider_location ON provider_profiles USING GIST (base_location);
-- Find verified providers within their configured service radius of customer (lon, lat)
SELECT user_id,
ST_Distance(base_location, ST_SetSRID(ST_MakePoint($1, $2), 4326)::geography) AS distance_m
FROM provider_profiles
WHERE is_verified = TRUE
AND ST_DWithin(
base_location,
ST_SetSRID(ST_MakePoint($1, $2), 4326)::geography,
service_radius_meters
)
ORDER BY distance_m ASC
LIMIT 20;
Eliminating Double-Bookings at the Database Layer
A classic race condition in early marketplaces happens during high demand: two customers tap Confirm Booking for the same 2:00 PM slot within 80 milliseconds. If your API merely runs SELECT count(*) ... and then INSERT, both transactions read zero conflicts and both succeed.
Solve this permanently with a PostgreSQL exclusion constraint (tstzrange):
CREATE TABLE bookings (
id UUID PRIMARY KEY,
customer_id UUID NOT NULL,
provider_id UUID NOT NULL,
slot TSTZRANGE NOT NULL,
status VARCHAR(24) NOT NULL, -- 'held' | 'confirmed' | 'in_progress' | 'completed' | 'cancelled'
CONSTRAINT no_overlapping_active_bookings
EXCLUDE USING gist (
provider_id WITH =,
slot WITH &&
)
WHERE (status IN ('held', 'confirmed', 'in_progress'))
);
Now PostgreSQL itself guarantees zero overlapping active bookings for any provider, even across ten horizontally scaled API containers. When a customer initiates checkout, insert a 'held' row with a 10-minute expiration job in Redis/BullMQ; if payment fails or times out, the worker flips the status to 'cancelled' and immediately frees the slot.
Enforcing the Booking State Machine
On-demand operations break when client apps send arbitrary status strings ("done", "cancelled"). Protect every transition with an explicit server-side state table and audit log:
const ALLOWED_TRANSITIONS: Record<string, string[]> = {
held: ['confirmed', 'cancelled'],
confirmed: ['en_route', 'cancelled'],
en_route: ['arrived', 'cancelled'],
arrived: ['in_progress', 'no_show'],
in_progress: ['completed', 'disputed'],
completed: ['disputed'],
};
export function assertValidTransition(current: string, next: string): void {
const allowed = ALLOWED_TRANSITIONS[current] ?? [];
if (!allowed.includes(next)) {
throw new Error(`Invalid booking transition: ${current} -> ${next}`);
}
}
Combine this with role checks (only the assigned provider can move confirmed -> en_route, while only an admin or verified OTP/PIN check can resolve disputed). Requiring a 4-digit job start/completion PIN shared verbally between customer and provider eliminates "provider marked job done without showing up" disputes.
Payments, Escrow, and Real-World Operations Admin
Following the Android app architecture guide and clean API boundaries, isolate billing behind a dedicated payment ledger rather than scattering Stripe webhooks across controllers:
- Authorization vs. Capture: For short on-demand jobs, authorize the estimated amount at dispatch and capture the final metered amount on completion. For scheduled multi-day services, capture into your platform balance and schedule a Stripe Connect transfer after a 24-hour dispute window.
- Webhook Idempotency: Store every incoming gateway event ID (
stripe_event_id) in a unique table column before mutating booking balances so duplicate webhook deliveries never double-credit a provider wallet. - Operations Admin Panel: Launch day one with a lightweight web console where support staff can reassign stalled jobs, override travel fees, issue partial refunds, and inspect provider KYC documents—this prevents founders from running SQL updates by hand at midnight.
Check our mobile app development guide for offline field sync patterns, or browse our shipped case studies to see marketplace systems in production.
Launch Your On-Demand Platform with SmitDev
At SmitDev, I build complete two-sided mobile ecosystems—Flutter or React Native apps for customers and providers, hardened Node.js/Laravel/FastAPI backends, PostGIS dispatch engines, and operations admin portals—drawing on 170+ shipped engagements since 2017.
Start with a structured launch consulting sprint to lock in unit economics, booking state machines, and compliance boundaries, or bring on dedicated senior full-stack engineering at $55/day (8–9 focused hours) or $1,999/month. Reach out via our contact page or review our mobile app development practice to scope your launch.