~/bpabatao
← back to index

Multi-Tenant Core API

The API behind the fleet's utility customer portals: two generations of it, and the migration from one to the other.

Role
Primary author of both generations, architecture and security owner
Period
2023 - present
Ownership
58% of v1 · 76% of v2
Stack
Fastify 5 · TypeScript (strict) · Zod · MongoDB · AWS SDK v3 · ECS Fargate · Vitest
deltamvunepdelcoalexrenewcarmelaruba7 portalsv1 → v2 on paritycore api v16 of 7 launchedexpresspatched + auditedcore api v27th + 1st migrationaccount-route authzper-tenant configoauth 2.0oracle ccs
7 tenant portals reach Oracle CCS over OAuth 2.0 through two generations of the core API: v1 serves six, v2 serves the seventh and runs beside v1 for the first migration, and a tenant moves when its parity checks pass

Problem

A fleet of utility companies each needed a customer portal that talks to Oracle Utilities CCS, the billing system of record. The v1 server I inherited when I joined in 2023 is an Express codebase that predates me (58% mine by commit today), and it had no clean way to vary behavior per tenant. Each new client meant forked code and another security audit.

The v2 rebuild started in early 2026 with two goals: adding a tenant should take configuration only, and an authorization mistake should be hard to ship by accident. Six of the seven launched tenants run production on v1 today, and the seventh launched directly on v2 in June 2026. The first v1-to-v2 migration runs v2 beside its v1 service, certified, with the cutover held. Tenants move one at a time.

Constraints

Utility customers pay their bills through this API, so it has to stay available and return correct data. Oracle CCS is reached over OAuth 2.0 with per-tenant credentials. The team is small, so the secure way to add a route had to be the default way, and the migration cannot pause billing.

Decisions

Architecture

Fastify 5 on Node 22, ESM-only, TypeScript strict with no any types. Zod validates input at the boundary, and responses share one fixed envelope so clients parse a single shape.

On v2, admin reads and impersonated sessions are audited as well as writes, attributed to the acting admin. The audit records which fields a write changed, and the v2 capture path deep-redacts tokens, passwords and identifiers. Admin writes are kept for a year, admin reads for ninety days.

Where the billing system of record and the payment provider disagree, a reconciler reports the drift first. Repairs run guarded and in shadow before they write, and the account-linking path guards against duplicate registrations and signup conflicts. Enforcing the ten-digit account number on one tenant's sign-in forms targeted about 215 CCS errors a day that partial or oversized numbers had been generating.

Typecheck, lint, tests and a Snyk gate run in CI; Bitbucket Pipelines builds to ECR and deploys to ECS Fargate behind a shared ALB.

Outcome

view resume ↗ (opens in new tab)email me