API Maker

The framework for AI era

Level 5 · GlobalArchitecture 13 of 13

Global enterprise platform

Every piece together: regions on several providers, customer data kept at home, shared state and one release flow.

The architecture large SaaS products grow into. Three regions on three providers serve users nearby, tenant databases stay in the region of their customers, and one API Maker DB and one Redis keep every region in step. Releases and events reach the whole world within seconds.

See it live

Every request is drawn as it travels. Slow it down, pause, go step by step, or open the full canvas and zoom in.

api-maker/architectures/global-enterpriseLive
  • Request
  • Response
  • Cache hit
  • Write
  • WebSocket event
  • Replication · reloads
  • Tenant acme
  • Tenant globex
  • Tenant initech
Regions
3on 3 providers
Workers
24CPU cores
Events
0pushed
Capacity
~16,554req/s

One platform: three regions, three providers. Users reach the nearest region, customers keep their data at home, and one API Maker serves them all.

How it works

The same steps as the diagram, in more detail.

  1. One platform: three regions, three providers.

    This is where the other architectures lead: API Maker on plain VPS of three providers, one region per continent, each with a pair of load balancers and API servers. Tenant databases stay in the region of their customers, and the regions share one API Maker DB and one Redis through a private backbone.

  2. Every user is served nearby.

    GeoDNS sends each user to the load balancers of the nearest region, where the API servers answer HTTP calls and hold WebSockets. Every region serves the same APIs from the same API Maker DB, so it does not matter which one a user lands on.

  3. Customer data stays in its region.

    The multi-tenant instance finds each tenant's connection string in the tenants table, and each tenant database runs in the region of its customer. Data residency rules are met by where the databases run, while one set of APIs, schemas and custom code serves every customer.

  4. One Redis and one API Maker DB for the world.

    The home region runs API Maker DB, the MongoDB primary and a Redis Cluster for every region, reached through encrypted tunnels between the providers. An event raised in Singapore reaches WebSocket clients in New York and Frankfurt, and a write anywhere clears the cached responses everywhere.

  5. One release reaches every region.

    Releases come from your Git repository, after DEV, QA and UAT. The pull runs on any one production server: the changes land in API Maker DB, and a cluster event through Redis makes every worker of every server, in every region, reload them within seconds.

  6. Peak season: more cores, more capacity.

    Each region scales on its own: resize its VPS and restart them one at a time, and API Maker starts one worker per core, or add servers behind its load balancers. In our benchmark, six 8-core servers answer about 27,000 requests per second.

Why choose this architecture

Near every user

Users reach the closest region for their HTTP calls and WebSockets, wherever they are.

Data residency

Each tenant database runs in the region of its customer, with the same APIs for every customer.

No provider can stop you

One provider per region: an outage, a price change or a new country is never a crisis.

One release flow

DEV, QA and UAT first, then one git pull reaches every server of every region.

Real time across continents

Events raised in any region reach WebSocket clients in every region through Redis.

Many products, one fleet

Several projects share the servers, each with its own APIs, users, secrets and databases.

Server configuration

Plain VPS from any provider, or your own servers, with Ubuntu 22.04 LTS. Sizes are a starting point: measure and adjust.

GeoDNS

×2
CPU
1 vCPU
Memory
1 GB
Storage
10 GB SSD

Runs

  • PowerDNS with the GeoIP backend
  • Or your DNS provider with geo routing

Ports

  • 53: from the internet

Load balancers

×2 per region
CPU
2 vCPU
Memory
2 GB
Storage
20 GB SSD

Runs

  • HAProxy and keepalived: an active and a standby

Ports

  • 443: on the floating IP of the region

API servers

×2+ per region
CPU
8 vCPU
Memory
16 GB
Storage
40 GB SSD

Runs

  • API Maker, cpuCount AUTO
  • The same .env in every region

Ports

  • 38246 and 38245: from the load balancers of the region

MongoDB members

×1 per region, ×2 at home
CPU
8 vCPU
Memory
32 GB
Storage
500 GB NVMe

Runs

  • One replica set: API Maker DB and shared data
  • The primary in the home region

Ports

  • 27017: private backbone only

Redis Cluster

×6, home region
CPU
4 vCPU
Memory
16 GB
Storage
20 GB SSD

Runs

  • Events, locks and cache of every region

Ports

  • 6379 and 16379: private backbone only

Tenant database servers

as needed, per region
CPU
8 – 16 vCPU
Memory
32 – 64 GB
Storage
1 TB NVMe

Runs

  • The databases of the customers of the region
  • A standby for the largest ones

Ports

  • From the API servers of the region only
Tenants table: each customer's database in its regiontenants
username   connection_stringacme       postgres://app:***@10.30.1.40:5432/acme       # Frankfurtglobex     postgres://app:***@10.30.2.40:5432/globex     # New Yorkinitech    postgres://app:***@10.30.3.40:5432/initech    # Singapore

API Maker keeps these connection strings encrypted in the table and decrypts them only to open a pool.

Every API server, in every region.env
am__serverName="nyc-api-2"   # region and server, to find it in the dashboardsam__cpuCount="AUTO"# The replica set over the three regions, the primary in Frankfurtam__mongo_db_connection="mongodb://api_maker:***@10.30.1.20:27017,10.30.1.21:27017,10.30.2.20:27017,10.30.3.20:27017/api_maker_db?authSource=admin&replicaSet=rs0"# Redis Cluster of the home region, for every regionam__redisInternal='{"nodes": [{host: "10.30.1.31", port: 6379, pass: "***"}, {host: "10.30.1.32", port: 6379, pass: "***"}, {host: "10.30.1.33", port: 6379, pass: "***"}]}'am__redisExternal='{"nodes": [{host: "10.30.1.31", port: 6379, pass: "***"}, {host: "10.30.1.32", port: 6379, pass: "***"}, {host: "10.30.1.33", port: 6379, pass: "***"}]}'

Good to know

  • The most servers and moving parts: automate provisioning, patching and monitoring from the first day.
  • Writes and shared state live in the home region: the other regions pay a round trip for them.
  • A tenant database is as available as its region: give the largest customers a standby next to it.
  • Costs add up over providers and regions. Grow into this one region, and one customer, at a time.

Questions

Do I need all of this?

Rarely at the start. Each piece comes from an architecture before it and can be added on its own: a second region, a tenant database in a new country, a third provider.

Can a customer move to another region?

Yes. Copy its database to the new region, update its row in the tenants table and call the multi-tenant-instance-updated system API: every server resets its pool for that tenant.

How are several products kept apart on the same servers?

As projects: each one has its own APIs, databases, secrets, users and roles on the same fleet, as the Multi-project architecture shows.