Architecture — Ingestion, Tenancy, Delivery
1. Ingestion fleet
Incumbent model = headless browser robots per bank portal (session login → parse mutation table). Keep it, harden it.
Scheduler (per-account cron)
↓ enqueue {account_id, provider, priority}
Worker pool (Playwright/Patchright, residential proxy per region)
↓ adapter[provider].fetch() → raw rows
Normalizer → dedupe (hash of bank_ref|date|amount|balance) → upsert
↓
Event bus → alert rules → channel fanout (email/TG/WA/webhook)
↓
Ledger: points charged per successful sync
Scale math (10k accounts, 5-min interval):
- 2.000 fetches/min ≈ 33/s, ~3,5 s/session → 117 concurrent sessions; 2 fat workers at 50 sessions each, or 117 lightweight containers.
- 109,5M mutation rows/yr ≈ 33 GB raw; 5-year retention ≈ 164 GB pre-compression (columnar + 3× compression → ~55 GB).
Non-negotiables:
- Credential vault: bank logins encrypted with per-tenant DEK, DEK wrapped by KMS; never in logs; break-glass audit event on every decrypt.
- Session reuse where the bank tolerates it; per-provider concurrency caps to avoid lockouts and account flags.
- Failure taxonomy: 401 (needs re-link → notify customer), 429 (backoff), layout change (adapter flag → alert on-call), network (retry ×3).
- Sandbox mode: seeded mutation simulator so demos and integration tests never touch real banks.
Ask the bank first: BRI/BCA/BNI publish SNAP BI statement APIs to licensed partners. Scraping is the fallback for long-tail accounts, SNAP is the enterprise path (see security.md).
2. Multi-tenancy
Model: shared schema + tenant_id + Postgres RLS, with per-tenant encryption for account credentials and optional dedicated DB for white-label enterprise.
| Concern | Decision |
|---|---|
| Isolation | RLS policy on every table; SET LOCAL app.tenant_id per request |
| Credentials | Envelope encryption, per-tenant DEK, KMS root |
| Rate limits | Per tenant + per API key, token bucket in Redis |
| Webhooks | Per-tenant queue + per-tenant signing secret; DLQ per tenant |
| White-label | Own domain (CNAME), own branding assets, own sender identity (email/WA) |
| Data residency | All in Indonesia region (Jakarta/Singapore); state in DPA |
| Deletion | Tenant hard-delete job with certificate; PDP right-to-erasure SLA 72h |
Cross-tenant leakage tests are part of CI, not a manual checklist: seed two tenants, attempt every read path as tenant A against tenant B's IDs — all must 404.
3. Webhook delivery
- Signed with HMAC-SHA256 (
X-Signature+ timestamp), replay window 5 min. - At-least-once with idempotency key; 5 retries exponential (10s → 30m), then DLQ + dashboard flag.
- Per-endpoint circuit breaker; auto-disable after 20 consecutive failures and email the tenant.
- Document a
replayendpoint — being able to re-push is a support-cost killer.
4. API design
x-api-keyscoped (read:mutations, write:accounts, admin) + per-key usage metering.- Cursor pagination on mutations; hard cap 500/page;
from/tofilters mandatory for >30-day ranges. - OpenAPI 3.1 spec is the source of truth; generate SDKs, docs, and an MCP tool schema from it.
5. Observability
Per-provider success rate, detection latency p95, alert delivery lag, points-ledger reconciliation delta (must be 0), webhook DLQ depth, credential decrypt count. Alert on "adapter parse yield drops >30% for 15 min" — that is how banks break you silently.
6. Stack (boring on purpose)
Postgres 16 + Redis + Scheduler (Celery/Temporal) + FastAPI + Next.js dashboard + Playwright workers + S3-compatible object store + KMS. No Kubernetes until 20k accounts; systemd + containers is enough. Ship the simulator and the sandbox early — they cut support load more than any feature.