Saya: Filling the Gap Between Bolt and DHL for Affordable On-Demand Heavy Goods Delivery
Technical Implementation
Saya is not just a marketplace - it is an intelligent logistics platform. Below is an overview of the technical architecture and the algorithmic decision-making layer built into the system.
| Algorithm | Input | Output | Complexity |
|---|---|---|---|
| Haversine Matching | lat/lng coordinates | Distance in km | O(n) |
| Offer Scoring | price, rating, distance | Score 0–1 | O(n) |
| Dynamic Pricing | weight, distance, day | Suggested price € | O(1) |
| ETA Prediction | distance, time, weekday | Duration in minutes | O(1) |
SYSTEM ARCHITECTURE
Saya is built on a modern full-stack architecture:
- Frontend: Next.js (React, TypeScript)
- Database: PostgreSQL with Drizzle ORM
- Payments: Stripe with webhook reconciliation
- Notifications: Resend (email)
- Shipment lifecycle: explicit state machine with transitions: created → offered → accepted → paid → picked up → in transit → delivered → completed
ALGORITHMIC FEATURES
- Geo-Aware Courier Matching Couriers see shipments sorted by proximity using the Haversine formula - pure mathematical distance calculation between two geographic coordinates, no external map API required.
Formula: d = 2r × arcsin(√(sin²(Δlat/2) + cos(lat1) × cos(lat2) × sin²(Δlon/2)))
Result: couriers see "2.7 km away" - nearest shipments appear first.
- Multi-Objective Offer Scoring When a customer receives offers, each offer is automatically scored:
score = 0.4 × price_score + 0.4 × courier_rating + 0.2 × distance_score
The top-scoring offer is marked "Recommended" with an explanation: higher rating, competitive price, closer location.
- Dynamic Pricing Suggestion When creating a shipment, the system suggests a fair price:
Suggested Price = Base Rate (5€) + Weight Factor (0.5€/kg) + Distance Factor (0.3€/km) + Weekend Multiplier (×1.2 on Sat/Sun)
The suggestion is non-binding where users can set their own price.
-
ETA Prediction Estimated delivery time is calculated from shipment distance, pickup time, and weekday/weekend factor. Predicted vs actual completion time is stored for accuracy analysis.
-
Logistics Intelligence Dashboard (Admin) An admin-only analytics section visualises real platform data:
- Courier distance distribution
- Suggested price vs accepted price comparison
- Offer recommendation acceptance rate
- ETA prediction accuracy
- Delivery completion statistics
WHY EXPLAINABLE ALGORITHMS?
Haversine: efficient, no external API dependency, stable approximation of route proximity.
// lib/matching.ts
// Haversine formula: calculates great-circle distance between two points
export function haversineDistance(
lat1: number, lng1: number,
lat2: number, lng2: number
): number {
const R = 6371; // Earth radius in km
const dLat = (lat2 - lat1) * Math.PI / 180;
const dLng = (lng2 - lng1) * Math.PI / 180;
const a = Math.sin(dLat/2) ** 2 +
Math.cos(lat1 * Math.PI/180) *
Math.cos(lat2 * Math.PI/180) *
Math.sin(dLng/2) ** 2;
return R * 2 * Math.asin(Math.sqrt(a));
}
Weighted scoring: courier selection is multi-objective cheaper is not necessarily better if rating or distance is poor.
Heuristic pricing: transparency beats complexity in logistics, users can understand and trust the suggestion.
Code modules:
lib/matching.ts · lib/offer-scoring.ts ·
lib/pricing.ts · lib/eta.ts · lib/analytics.ts