# ROUTD: Scaling Last-Mile Logistics

> How we rebuilt a multi-tenant SaaS logistics platform for last-mile delivery: a team of 8 replaced 1.5 years of custom code in 6 months, and the platform now handles 30,000+ orders a month on a cloud bill under $700. A full platform rebuild with dedicated engineering, cloud architecture, and real-time tracking across mobile and web.

Page: https://www.leafcompute.com/case-studies/routd

Client: ROUTD
Industry: Logistics & Delivery
- 6 months: to rebuild 1.5 years of custom code
- 8: engineers in the team we led
- 30,000+: orders delivered a month
- < $700: cloud bill while handling them

## The Problem

ROUTD had a real business: around $5M worth of orders a year, and customers like Compass Group and Ole & Steen depending on them for last-mile delivery across the UK. But after 1.5 years of iterative development, the codebase was a liability.

The system worked, but only just: real-time tracking was flaky, route optimization was slow, multi-tenancy had been bolted on and cloud costs were climbing. The team knew they needed a full rebuild, but they couldn't afford to stop shipping.

They needed a team that would rebuild the platform without losing velocity and own the code it wrote.

## The Architecture

We led a team of 8 and rebuilt the platform in 6 months: a ground-up redesign of 1.5 years of custom development.

<div style="margin: 2rem 0; padding: 2rem; background: #FFFFFF; border: 1px solid #E5E5E5; border-radius: 12px;">
<svg viewBox="0 0 800 400" fill="none" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;font-family:system-ui,sans-serif;">
  <defs>
    <filter id="shadowR" x="-20%" y="-20%" width="140%" height="140%">
      <feDropShadow dx="0" dy="2" stdDeviation="4" flood-color="#000" flood-opacity="0.08"/>
    </filter>
    <marker id="arrowhead" markerWidth="10" markerHeight="10" refX="9" refY="5" orient="auto">
      <path d="M0 0L10 5L0 10" fill="none" stroke="#111110" stroke-width="2"/>
    </marker>
  </defs>
  <text x="400" y="26" fill="#111110" font-size="18" font-weight="bold" text-anchor="middle">ROUTD Platform Architecture</text>
  <rect x="340" y="32" width="120" height="3" rx="1.5" fill="#FFD41D"/>
  <rect x="50" y="60" width="140" height="80" rx="8" fill="white" stroke="#111110" stroke-width="2" filter="url(#shadowR)"/>
  <rect x="50" y="60" width="8" height="80" rx="2" fill="#FFD41D"/>
  <text x="125" y="95" fill="#111110" font-size="14" font-weight="bold" text-anchor="middle">Driver Mobile</text>
  <text x="125" y="115" fill="#666666" font-size="11" text-anchor="middle">React Native</text>
  <rect x="50" y="160" width="140" height="80" rx="8" fill="white" stroke="#111110" stroke-width="2" filter="url(#shadowR)"/>
  <rect x="50" y="160" width="8" height="80" rx="2" fill="#FFD41D"/>
  <text x="125" y="195" fill="#111110" font-size="14" font-weight="bold" text-anchor="middle">Admin Dashboard</text>
  <text x="125" y="215" fill="#666666" font-size="11" text-anchor="middle">React + TypeScript</text>
  <rect x="270" y="100" width="160" height="100" rx="8" fill="#111110" stroke="#111110" stroke-width="2" filter="url(#shadowR)"/>
  <rect x="270" y="100" width="6" height="100" rx="2" fill="#FFD41D"/>
  <text x="350" y="128" fill="#FFFFFF" font-size="14" font-weight="bold" text-anchor="middle">API Gateway</text>
  <text x="350" y="148" fill="#999999" font-size="11" text-anchor="middle">.NET Web API</text>
  <text x="350" y="168" fill="#DDDDDD" font-size="10" text-anchor="middle">• Global tenant filter</text>
  <text x="350" y="183" fill="#DDDDDD" font-size="10" text-anchor="middle">• Auth + rate limiting</text>
  <rect x="270" y="220" width="160" height="80" rx="8" fill="white" stroke="#111110" stroke-width="2" filter="url(#shadowR)"/>
  <rect x="270" y="220" width="8" height="80" rx="2" fill="#FFD41D"/>
  <text x="350" y="252" fill="#111110" font-size="14" font-weight="bold" text-anchor="middle">Event Bus</text>
  <text x="350" y="272" fill="#666666" font-size="11" text-anchor="middle">Azure Service Bus</text>
  <rect x="500" y="60" width="220" height="240" rx="12" fill="white" stroke="#111110" stroke-width="2" filter="url(#shadowR)"/>
  <rect x="500" y="60" width="6" height="240" rx="2" fill="#FFD41D"/>
  <text x="520" y="85" fill="#111110" font-size="12" font-weight="bold">Core Microservices</text>
  <rect x="520" y="100" width="180" height="50" rx="4" fill="#FFFDF5" stroke="#FFD41D" stroke-width="1.5"/>
  <text x="610" y="130" fill="#111110" font-size="12" text-anchor="middle" font-weight="600">Order Management</text>
  <rect x="520" y="160" width="180" height="50" rx="4" fill="#FFFDF5" stroke="#FFD41D" stroke-width="1.5"/>
  <text x="610" y="190" fill="#111110" font-size="12" text-anchor="middle" font-weight="600">Route Optimization</text>
  <rect x="520" y="220" width="180" height="50" rx="4" fill="#FFFDF5" stroke="#FFD41D" stroke-width="1.5"/>
  <text x="610" y="250" fill="#111110" font-size="12" text-anchor="middle" font-weight="600">Tracking Service</text>
  <path d="M190 100 L270 140" stroke="#111110" stroke-width="2.5" marker-end="url(#arrowhead)"/>
  <path d="M190 200 L270 160" stroke="#111110" stroke-width="2.5" marker-end="url(#arrowhead)"/>
  <path d="M430 150 L520 125" stroke="#111110" stroke-width="2.5" marker-end="url(#arrowhead)"/>
  <path d="M430 150 L520 185" stroke="#111110" stroke-width="2.5" marker-end="url(#arrowhead)"/>
  <path d="M430 150 L520 245" stroke="#111110" stroke-width="2.5" marker-end="url(#arrowhead)"/>
  <path d="M430 260 L520 255" stroke="#FFD41D" stroke-width="2.5" stroke-dasharray="4 4"/>
</svg>
</div>

### Stack Choices

**Backend: .NET Web API + Azure Functions**

We chose .NET because the team already had C# experience, and we needed something that could handle synchronous request/response at scale. The Web API layer handles all CRUD operations, auth, and tenant isolation.

Azure Functions handle the expensive operations: route optimization, ETA calculation with third-party APIs, and notification delivery. These workloads are bursty, and a route optimizer has no reason to run 24/7, so serverless was the better fit.

**Frontend: React Dashboard + React Native Mobile**

The admin dashboard is React with TypeScript. Real-time driver tracking uses WebSockets for live position updates. The mobile app is React Native, a single codebase for iOS and Android. That mattered because the team was small and couldn't afford separate native engineers.

**Database: Azure SQL with Multi-Tenancy**

We implemented multi-tenancy at the database level with global query filters. Every table has a `TenantId` column. Every query automatically includes `WHERE TenantId = @CurrentTenant` via EF Core's global filters. This prevents data leakage between customers without maintaining separate databases.

Row-level security in SQL Server adds a second layer of defense. Even if the application layer fails, the database won't return cross-tenant data.

## Timeline

The rebuild reached its MVP in 6 months, inside an engagement that ran for more than a year. We led a team of 8 through it, replacing 1.5 years of custom development with a platform designed for the scale ROUTD was heading towards.

## Key Engineering Decisions

### 1. Multi-Tenant Data Isolation

<div style="margin: 2rem 0; padding: 2rem; background: #FFFFFF; border: 1px solid #E5E5E5; border-radius: 12px;">
<svg viewBox="0 0 800 320" fill="none" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;font-family:system-ui,sans-serif;">
  <defs>
    <filter id="shadowMT" x="-20%" y="-20%" width="140%" height="140%">
      <feDropShadow dx="0" dy="2" stdDeviation="4" flood-color="#000" flood-opacity="0.08"/>
    </filter>
    <marker id="arrowMT" markerWidth="10" markerHeight="10" refX="9" refY="5" orient="auto">
      <path d="M0 0L10 5L0 10" fill="none" stroke="#FFD41D" stroke-width="2"/>
    </marker>
  </defs>
  <text x="400" y="26" fill="#111110" font-size="18" font-weight="bold" text-anchor="middle">Multi-Tenant Data Isolation Strategy</text>
  <rect x="270" y="32" width="260" height="3" rx="1.5" fill="#FFD41D"/>
  <rect x="50" y="60" width="700" height="80" rx="8" fill="white" stroke="#111110" stroke-width="2" filter="url(#shadowMT)"/>
  <rect x="50" y="60" width="8" height="80" rx="2" fill="#FFD41D"/>
  <text x="400" y="88" fill="#111110" font-size="15" font-weight="bold" text-anchor="middle">Application Layer: Global Query Filters</text>
  <text x="120" y="113" fill="#111110" font-size="11" text-anchor="start">• EF Core global filter on every DbSet</text>
  <text x="120" y="128" fill="#666666" font-size="11" text-anchor="start">• TenantId injected from JWT claims</text>
  <text x="450" y="113" fill="#111110" font-size="11" text-anchor="start">• Applied automatically to all queries</text>
  <text x="450" y="128" fill="#666666" font-size="11" text-anchor="start">• Can't be accidentally bypassed</text>
  <rect x="50" y="160" width="700" height="80" rx="8" fill="#111110" stroke="#111110" stroke-width="2" filter="url(#shadowMT)"/>
  <rect x="50" y="160" width="8" height="80" rx="2" fill="#FFD41D"/>
  <text x="400" y="188" fill="#FFFFFF" font-size="15" font-weight="bold" text-anchor="middle">Database Layer: Row-Level Security</text>
  <text x="120" y="213" fill="#DDDDDD" font-size="11" text-anchor="start">• SQL Server RLS policies on all tables</text>
  <text x="120" y="228" fill="#999999" font-size="11" text-anchor="start">• Security function checks SESSION_CONTEXT</text>
  <text x="450" y="213" fill="#DDDDDD" font-size="11" text-anchor="start">• Database-level enforcement</text>
  <text x="450" y="228" fill="#999999" font-size="11" text-anchor="start">• Protects against SQL injection</text>
  <rect x="50" y="270" width="700" height="40" rx="6" fill="#FFFDF5" stroke="#FFD41D" stroke-width="2"/>
  <text x="70" y="295" fill="#666666" font-size="11" font-family="monospace">var orders = await _context.Orders.Where(o => o.Status == "Pending").ToListAsync();</text>
  <text x="400" y="260" fill="#111110" font-size="11" font-weight="600" text-anchor="middle">↓ Automatically secured ↓</text>
</svg>
</div>

A multi-tenant platform has to choose between a separate database per customer and a shared database with tenant isolation.

Separate databases are safer but expensive to operate. A shared database is efficient, but one bad query can leak data across customers.

We chose shared database with **two layers of isolation**: application-level global filters and database-level row-level security.

In EF Core, we applied a global filter to every entity:

```csharp
modelBuilder.Entity<Order>().HasQueryFilter(o => o.TenantId == _currentTenant.Id);
```

Every query then includes the tenant filter automatically, so developers can't forget to add it or bypass it by accident.

At the database level, we added SQL Server row-level security policies:

```sql
CREATE SECURITY POLICY TenantSecurityPolicy
ADD FILTER PREDICATE dbo.fn_TenantAccessPredicate(TenantId) ON dbo.Orders
WITH (STATE = ON);
```

Even if someone writes raw SQL, the database won't return cross-tenant data.

That gave ROUTD the simpler operations of a shared database, with tenant isolation enforced in two places.

### 2. Cloud Cost Optimization

The rebuilt platform runs on a cloud bill **under $700** while handling **30,000+ orders** a month.

**Serverless for bursty work.** Route optimization only runs when a new delivery batch comes in, maybe 50 times a day, which suits Azure Functions well. We pay for execution time and have no idle servers to pay for.

**Right-sized databases.** We moved from a General Purpose tier to a Basic tier for non-production environments. Production stayed on Standard tier but with auto-pause enabled during low-traffic hours.

**CDN for static assets.** Images, maps and driver profile photos are served from Azure CDN with aggressive caching.

**Third-party API batching.** Instead of calling the ETA API for every address update, we batch requests every 2 minutes, so the bill tracks deliveries rather than GPS pings.

Each of these was a deliberate design choice, and together they keep infrastructure a small cost for a platform handling 30,000+ orders a month. This is the kind of [cloud architecture](/services/cloud-architecture) work we do, and the money ROUTD doesn't spend on infrastructure can go toward growth.

### 3. Real-Time Tracking Without the Database Bottleneck

<div style="margin: 2rem 0; padding: 2rem; background: #FFFFFF; border: 1px solid #E5E5E5; border-radius: 12px;">
<svg viewBox="0 0 800 350" fill="none" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;">
  <text x="400" y="30" fill="#111110" font-size="18" font-weight="600" text-anchor="middle">Real-Time Location Updates Architecture</text>
  <rect x="50" y="60" width="140" height="80" rx="8" fill="#F5F5F5" stroke="#333333" stroke-width="2"/>
  <text x="120" y="95" fill="#111110" font-size="13" font-weight="600" text-anchor="middle">Driver App</text>
  <text x="120" y="113" fill="#666666" font-size="10" text-anchor="middle">GPS update</text>
  <text x="120" y="127" fill="#666666" font-size="10" text-anchor="middle">every 10 seconds</text>
  <rect x="270" y="60" width="160" height="120" rx="8" fill="#111110" stroke="#111110" stroke-width="2"/>
  <text x="350" y="90" fill="#FFFFFF" font-size="14" font-weight="600" text-anchor="middle">SignalR Hub</text>
  <text x="350" y="108" fill="#999999" font-size="11" text-anchor="middle">WebSocket server</text>
  <text x="285" y="130" fill="#FFFFFF" font-size="10">• Validates tenant</text>
  <text x="285" y="145" fill="#FFFFFF" font-size="10">• Broadcasts to group</text>
  <text x="285" y="160" fill="#FFFFFF" font-size="10">• Rate limits updates</text>
  <rect x="270" y="200" width="160" height="80" rx="8" fill="#F5F5F5" stroke="#333333" stroke-width="2"/>
  <text x="350" y="230" fill="#111110" font-size="13" font-weight="600" text-anchor="middle">Redis Cache</text>
  <text x="350" y="248" fill="#666666" font-size="10" text-anchor="middle">Latest position only</text>
  <text x="350" y="262" fill="#666666" font-size="10" text-anchor="middle">TTL: 1 hour</text>
  <rect x="510" y="200" width="160" height="80" rx="8" fill="#111110" stroke="#111110" stroke-width="2"/>
  <text x="590" y="230" fill="#FFFFFF" font-size="13" font-weight="600" text-anchor="middle">SQL Database</text>
  <text x="590" y="248" fill="#999999" font-size="10" text-anchor="middle">Batched writes</text>
  <text x="590" y="262" fill="#999999" font-size="10" text-anchor="middle">every 5 minutes</text>
  <rect x="510" y="60" width="160" height="80" rx="8" fill="#F5F5F5" stroke="#333333" stroke-width="2"/>
  <text x="590" y="95" fill="#111110" font-size="13" font-weight="600" text-anchor="middle">Admin Dashboard</text>
  <text x="590" y="113" fill="#666666" font-size="10" text-anchor="middle">Live map view</text>
  <text x="590" y="127" fill="#666666" font-size="10" text-anchor="middle">30+ drivers tracked</text>
  <path d="M 190 100 L 270 110" stroke="#111110" stroke-width="2" marker-end="url(#arr3)"/>
  <text x="230" y="95" fill="#666666" font-size="9">10s interval</text>
  <path d="M 430 110 L 510 100" stroke="#111110" stroke-width="2" marker-end="url(#arr3)"/>
  <text x="455" y="95" fill="#333333" font-size="9">WebSocket</text>
  <path d="M 350 180 L 350 200" stroke="#111110" stroke-width="2" marker-end="url(#arr3)"/>
  <text x="365" y="195" fill="#666666" font-size="9">Write-through</text>
  <path d="M 430 240 L 510 240" stroke="#111110" stroke-width="2" marker-end="url(#arr3)"/>
  <text x="455" y="235" fill="#666666" font-size="9">Batch insert</text>
  <defs>
    <marker id="arr3" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
      <polygon points="0 0, 10 3, 0 6" fill="#111110" />
    </marker>
  </defs>
  <rect x="50" y="300" width="700" height="35" rx="6" fill="#FFFFFF" stroke="#E5E5E5" stroke-width="1"/>
  <text x="70" y="323" fill="#111110" font-size="11" font-weight="600">Result:</text>
  <text x="130" y="323" fill="#666666" font-size="10">Sub-second latency for live tracking</text>
  <text x="350" y="323" fill="#666666" font-size="10">Batched writes to the database</text>
  <text x="570" y="323" fill="#666666" font-size="10">Zero location data loss</text>
</svg>
</div>

The original system wrote every GPS update directly to the database. When you have 30 drivers on the road, each sending location updates every 10 seconds, that's **180 writes per minute** just for location tracking.

We decoupled real-time display from durable storage.

Driver apps send GPS updates to a SignalR hub via WebSockets. The hub validates the tenant, broadcasts the update to all connected dashboards, and writes the latest position to Redis.

Every 5 minutes, a background job reads from Redis and batch-inserts location history into SQL. Live tracking stays real-time on the map while the database takes far fewer writes.

Admin dashboards connect to the SignalR hub and receive location updates as they happen, without polling, so the map shows each driver's current position.

### 4. Route Optimization Without Vendor Lock-In

The previous system paid a third-party route optimization API for every route calculation, which gets expensive at 30,000+ orders a month.

We built a custom route optimizer using the Traveling Salesman Problem (TSP) with a greedy nearest-neighbor heuristic. It doesn't find the perfect route every time, but it replaced manual route assignment.

For complex routes (15+ stops), we fall back to the third-party API. For simple routes (3-8 stops), we use our own algorithm. This hybrid approach keeps most routes off the paid API without losing quality on the hard ones.

The optimizer runs as an Azure Function triggered when a new delivery batch is created. It takes a list of addresses, calculates optimal visit order, estimates ETAs based on traffic data, and returns a route manifest.

## The Results

We rewrote 1.5 years of custom development in **6 months**, leading a team of 8. The platform now handles:

- **30,000+ orders delivered per month**
- **Around $5M worth of orders a year**
- **A cloud bill under $700**

ROUTD is used by companies including **Compass Group** and **Ole & Steen** for their last-mile delivery operations across the UK.

## Beyond the Code

Alongside the software, we embedded with the ROUTD team and worked on:

**Pricing strategy.** We modeled customer pricing based on order volume, data growth, third-party API costs, and infrastructure spend. That gave ROUTD a pricing breakdown per customer built on data growth, third-party, development, maintenance and cloud costs.

**Monitoring and chaos engineering.** We set up Grafana dashboards with SLA-driven alerts. We ran chaos experiments, such as killing database connections, simulating API timeouts and injecting latency into WebSocket connections, to test failure modes before customers hit them.

**Business guidance.** We consulted on HCI principles for driver UX, advised on GDPR compliance for location data retention, and analyzed user behavior patterns to improve onboarding flows.

**Sales enablement.** We helped the sales team demo the platform by building a sandbox environment with realistic test data. We also created technical sales collateral explaining the multi-tenant architecture to enterprise buyers.

**Build vs. buy decisions.** We identified areas where renting third-party services (SMS delivery, push notifications, map rendering) saved tens of thousands in unnecessary development costs.

This is how we run [dedicated engineering](/services/dedicated-engineering). Our engineers sit in your Slack, push to your repo and own the outcomes alongside your team. When something breaks at 2am, we're in the incident channel. When the engagement ends, you keep the code, the architecture, the CI/CD pipelines and a team that now knows how to maintain it.

## What We'd Do Differently

If we rebuilt this today, we'd consider:

**Event sourcing for order state.** Right now, order status is a single column that gets updated in place. If we tracked order state as an append-only event log, we'd get built-in audit trails and better debugging when customers ask "why was this order marked as delivered at 3pm when the driver says they delivered it at 2pm?"

**GraphQL instead of REST.** The dashboard makes 8-10 REST calls on page load to fetch orders, drivers, routes, and analytics. A single GraphQL query could fetch everything in one round-trip.

**Edge functions for geofencing.** We run geofence calculations (is the driver inside the delivery zone?) in Azure Functions. Moving this to Cloudflare Workers or Deno Deploy would reduce latency for real-time alerts.

None of these is blocking anything today; the platform works, scales and makes money as it is.

## Summary

ROUTD had a working product and paying customers, but the codebase couldn't scale and the team couldn't ship fast enough.

We led a team of 8, rebuilt the platform in 6 months and shipped it to production. On [dedicated engineering](/services/dedicated-engineering) work we write the code, own the architecture and stay until it's running.

If your platform is hitting a ceiling and you want engineers who will build the fix, [join us on Discord](https://discord.gg/EVEyT7g7sc) and tell us what you're working on. You can also read about our [cloud architecture](/services/cloud-architecture) and [dedicated engineering](/services/dedicated-engineering) services to see how we work.

---
Leaf Compute: https://www.leafcompute.com · hello@leafcompute.com
