Architecting Sub-20ms Developer Data APIs with Next.js, Edge CDN & Prisma
How we engineered UpraiserTech's developer data platform to serve 240+ countries, 150+ Nigerian banks, and 774 LGAs with sub-20ms global latency.
The Problem: Fragmented African Metadata
When developers in Nigeria and across Africa build fintech onboarding, KYC verification, or delivery routing systems, they hit an immediate wall: - Bank routing codes and CBN slugs are scattered across outdated PDF circulars. - Local Government Area (LGA) spellings vary between government agencies. - Geopolitical zones and university codes lack standardized JSON representations.
To solve this, I founded **UpraiserTech** — a developer-first data platform providing validated REST APIs and downloadable datasets. However, because our APIs are invoked during checkout and onboarding flows, high latency was unacceptable.
Here is the exact architectural strategy used to achieve **sub-14ms average query latency**.
1. Dual-Layer Caching Strategy
The most performant database query is the one you never execute. For reference data (such as 774 Nigerian LGAs or 240 country codes), the data rarely mutates hourly.
We implemented an Edge CDN caching header protocol on our Next.js API route handlers:
// app/api/v1/banks/route.js
export async function GET(req) {
const { searchParams } = new URL(req.url);
const country = searchParams.get('country') || 'NG';const banks = await getCachedBanks(country);
return new Response(JSON.stringify({ success: true, count: banks.length, data: banks }), { status: 200, headers: { 'Content-Type': 'application/json', // Edge cache for 24 hours, stale-while-revalidate for 7 days 'Cache-Control': 'public, s-maxage=86400, stale-while-revalidate=604800', 'CDN-Cache-Control': 'max-age=86400' } }); } ```
When a request arrives from London, Lagos, or New York, the closest Edge CDN node serves the cached JSON envelope in **11ms to 14ms**, without waking the primary PostgreSQL instance.
2. Relational Modeling with Prisma ORM
For authenticated developer endpoints requiring API key verification, HMAC signature validation, and hourly quota tracking (1,000 req/hr on the free tier), queries must hit our PostgreSQL cluster.
We optimized database indexes on high-frequency lookup fields: - Indexed `apiKey` hash in the `ApiKey` table. - Composite indexes on `[countryCode, isActive]` for financial institutions. - Connection pooling with Prisma to eliminate cold-start handshake overhead.
3. Predictable Response Envelopes
Every single endpoint on UpraiserTech adheres to a standardized response contract: ```json { "success": true, "message": "Data retrieved successfully", "data": [ ... ], "pagination": { "page": 1, "limit": 50, "total": 156 }, "metadata": { "latencyMs": 11, "region": "LOS1" } } ```
This consistency ensures that multi-language SDKs (JavaScript, Python, Flutter, Go) can parse responses cleanly with zero runtime exceptions.