Scaling Wasm: The LetX Engineering Handbook
How we ported 5GB of TeX Live to the browser, and why WebAssembly is the future of complex web apps.
Multi-tenant SaaS on AWS ECS Fargate with Terraform isolates tenants while sharing infrastructure — here's the pattern Shahriar Labs uses in production.
Multi-tenant SaaS on AWS ECS Fargate with Terraform isolates tenants while sharing infrastructure — reducing per-tenant cost while maintaining security boundaries. This is the pattern Shahriar Labs uses for production SaaS builds, refined across multiple client projects.
The right isolation model depends on compliance requirements and tenant size distribution. For most B2B SaaS: shared ECS cluster with per-tenant task definitions, row-level security (RLS) in PostgreSQL with tenant_id on every table, and separate S3 prefixes per tenant. This covers 80% of tenants at minimal infrastructure cost.
Enterprise tenants with compliance requirements (HIPAA, SOC 2 Type II, financial sector) need stronger isolation: separate RDS instances or schemas, separate VPCs or at minimum separate security groups, and separate AWS accounts for the largest contracts. Design your tenant module to support both — parameterize isolation level, not implement two separate stacks.
The core Terraform structure:
module "tenant" {
source = "./modules/tenant"
tenant_id = "acme-corp"
tier = "enterprise" # "starter" | "growth" | "enterprise"
region = "ap-southeast-1"
}
The module provisions: RDS schema (or instance for enterprise), IAM role with tenant-scoped S3 policy, ECS task definition with tenant env vars injected via Secrets Manager, and Route53 subdomain (acme-corp.yourapp.com). Adding a tenant is a one-line Terraform call.
Schema migrations across hundreds of tenant schemas require a migration runner that: iterates tenant list from the database, applies migrations tenant-by-tenant with rollback on failure, skips already-migrated tenants (idempotent), and publishes migration status to a monitoring dashboard. Never run raw ALTER TABLE across all tenants in a single transaction — a lock on one tenant's table blocks all others.
For the workflow orchestration layer, see our post on using Temporal for reliable GenAI pipelines. For always-on agent infrastructure on AWS, see hermes-agent-aws.
Written by Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs. Building LetX, QuantumSketch, and open-source AI agent skills.