DEV Community

Cover image for How We Built a Cloud Retail ERP That Handles 10x Faster Billing with Next.js & Edge Functions
Royal Task
Royal Task

Posted on Originally published at royalemerging.com

How We Built a Cloud Retail ERP That Handles 10x Faster Billing with Next.js & Edge Functions

Originally published on the Royal Emerging Engineering Blog. Royal Emerging is a global IT consulting and engineering firm specializing in enterprise Next.js platforms, cloud-native ERP systems, and AI-powered workflow automations.


The Problem: Legacy Retail Billing Is Painfully Slow

If you have ever stood in a busy supermarket queue watching the cashier struggle with a frozen billing terminal, you understand the problem we set out to solve. Most retail Point-of-Sale (POS) systems in emerging markets run on decades-old desktop software β€” think Visual Basic or Delphi applications connecting to a local MS Access or MySQL database on the same machine.

The consequences are brutal:

  • Checkout latency of 8–15 seconds per transaction during peak hours
  • Zero real-time visibility into stock levels across multiple branches
  • No cloud access β€” the owner physically needs to be at the store to check sales
  • Catastrophic data loss risk when the billing PC hard drive fails

We decided to engineer RE Management Retail & Inventory ERP β€” a modern, cloud-native platform purpose-built for high-throughput retail environments.

πŸ‘‰ Try the Live Demo: is.royalemerging.com


Architecture Decision: Why Next.js + Edge Functions?

When we evaluated frameworks, the requirements were non-negotiable:

Requirement Why It Matters
Sub-second billing response Cashiers process 200+ transactions/day. Every second counts.
Multi-branch real-time sync Franchise owners need live inventory across 5–50 locations
Mobile-first dashboard Store owners monitor sales from their phone, not a desktop
Offline resilience Internet drops in emerging markets are common

Why Not a Traditional SPA + REST API?

A conventional React SPA calling a centralized REST API introduces latency at every hop β€” DNS resolution, TLS handshake, API gateway routing, database query, serialization, and client-side rendering. For a billing terminal that needs to feel instantaneous, this architecture simply doesn't work at scale.

The Edge-First Architecture

Instead, we deployed Next.js App Router with Edge Runtime functions on Vercel's global edge network. Here's what this unlocks:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  POS Terminal │────▢│  Edge Function   │────▢│  Turso SQLite β”‚
β”‚  (Browser)    │◀────│  (nearest PoP)   │◀────│  (Edge DB)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                                            β”‚
       β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
       └─────────────▢│  Service Worker  β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚  (Offline Queue) β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Key technical decisions:

  1. Edge Functions for billing mutations β€” The POST /api/invoice endpoint runs at the nearest edge PoP (< 50ms globally), not a centralized US-East server
  2. Turso (libSQL) as the edge database β€” Embedded SQLite replicas at edge locations with automatic replication to the primary
  3. Service Worker offline queue β€” When internet drops, transactions queue locally and sync when connectivity returns
  4. Server Components for the dashboard β€” The owner's analytics dashboard streams HTML from the server, eliminating client-side loading spinners

The 10x Billing Speed Result

After deploying this architecture to production retail stores, we benchmarked against the legacy system:

Metric Legacy Desktop POS RE Management (Edge) Improvement
Invoice generation 8.2s avg 0.7s avg 11.7x faster
Stock lookup 3.1s 0.2s 15x faster
Daily report generation 45s 1.8s 25x faster
Multi-branch inventory sync Manual (hours) Real-time (< 500ms) ∞

Key Takeaways for Your Own Projects

  1. Move billing mutations to the edge. If your users are globally distributed or in regions with high latency, edge functions eliminate the round-trip penalty.

  2. Embedded edge databases are production-ready. Turso, Cloudflare D1, and PlanetScale edge caching have matured significantly in 2026. Use them.

  3. Offline-first is not optional for retail. Service Workers with background sync are table stakes for any POS application.

  4. Server Components eliminate dashboard loading states. For data-heavy admin panels, streaming HTML from the server provides a dramatically better user experience than client-side data fetching.


Try It Yourself

The full RE Management Retail & Inventory ERP is available as a live interactive demo:

πŸš€ Launch Live Demo β†’ is.royalemerging.com

πŸ“Š Explore Our Full Engineering Portfolio β†’ royalemerging.com

πŸ› οΈ Free Interactive Web Utilities (Zero Watermark):


This article was authored by the Architecture & Engineering team at Royal Emerging β€” a global IT consulting firm specializing in enterprise Next.js platforms, cloud ERP systems, and AI-powered workflow automations. For technical consulting inquiries, reach us at info@royalemerging.com or WhatsApp.

Top comments (0)