Under the hood · The Lighthouse
Under the hood
This site runs on its own backend, and this page shows how: the live status, the architecture, what it costs and why it was built this way.
System status
A probe from your browser through the same paths production uses: edge, API, DynamoDB and the real-time WebSocket.
Your request
- edge pop
- …
- api
- …
- dynamodb
- …
- realtime /rt
- …
- viewer country
- …
Real-time server · every second
Connecting to the real-time server…
listening…
Architecture
One static site, a few serverless handlers, and a single stateful real-time server hidden behind CloudFront.
- /* → S3
- Static pages and hashed 3D assets, served privately through CloudFront.
- /api/* → Lambda
- Contact form, garden, stats and post reactions as small serverless handlers.
- /rt → EC2
- One stateful Node.js process holds the live world in memory and talks WebSockets.
- State
- DynamoDB and S3 hold everything durable, so the server itself is disposable.
- Scheduled jobs
- EventBridge Scheduler triggers Lambdas for probes and nightly aggregates.
- Egress
- SSM and CloudWatch are reached over IPv6 (egress-only gateway), with no NAT gateway.
Designed for 1,000 players on a $2 server
The server is a t4g.nano: 2 vCPUs and 0.5 GB of RAM. These are the design targets it is built around.
Impact at a glance
~8 B
per entity per update
~4 KB/s
budget per player in the world (measured: ~1.9 KB/s)
~4 MB/s
budget at 1,000 players (about 14 GB an hour)
100
players per world layer
01
Send less
The hot path is binary: 8 bytes per entity. That is a 16-bit id, position quantised to 16 bits on each axis, yaw to 8 bits and a one-byte animation state.
02
Send only what changed nearby
A spatial hash grid of 16 m cells, each cell a pub/sub topic. One update is encoded per changed cell per tick, so cost grows with active cells rather than players squared.
03
Shard the world
World layers are capped at 100 players and created automatically. Presence counts stay global.
04
Shed load
Snapshots go out at a fixed 10 Hz. Each connection has a message budget, and a client that falls too far behind is disconnected instead of slowing everyone else. A cap on how many avatars each client sees, and a spectator queue for when the server is full, are planned.
05
Keep the box disposable
Durable state lives only in DynamoDB and S3. Deploys drain the old process while a new one binds the same port, and systemd restarts a crashed one.
06
Cap the bill
CPU credits are set to standard, a hard cost ceiling, so a burst can slow the server but never raise the invoice.
Measured locally with bots: 1,000 of them in the 3D world with zero errors and a world tick of about 10 ms at p99, and everyone back within about 4 seconds after a restart, a crash and a database outage. The details are in the case study and in the chaos test write-up.
What it costs
Estimated monthly cost in Mumbai (ap-south-1), in US dollars.
| Item | $/month |
|---|---|
| EC2 t4g.nano on-demand | 2.04 |
| EBS gp3 8 GB | 0.73 |
| Route 53 hosted zone | 0.50 |
| S3 (site, snapshots, ghosts, releases) | ~0.10 |
| DynamoDB on-demand + point-in-time recovery (tiny table) | ~0.05 |
| CloudFront (up to 1 TB, 10M requests, 2M Function runs) | 0 (always free) |
| Lambda, Scheduler, SSM, CloudWatch (up to 10 alarms, 5 GB logs), SES, VPC/IGW/EIGW/endpoints/VPC origin | 0 |
| Total at portfolio traffic | ≈ $3.40 |
- The domain renewal is a separate yearly bill.
- A 1-year Compute Savings Plan would cut the EC2 cost by about 30%.
- If 512 MB of RAM proves tight, a t4g.micro brings the total to about $5.45.
Tech stack
- Frontend
- Next.js 16 (static export) · React 19 · TypeScript · Tailwind CSS v4 · MDX + Shiki · Pagefind
- 3D world
- three.js (WebGL2) · React Three Fiber + drei · postprocessing · troika-three-text · suncalc
- Real-time core
- Node.js 24 · uWebSockets.js · Binary protocol · Interest management grid
- API
- AWS Lambda (arm64) · Function URLs · zod contracts · Amazon SES
- Data
- DynamoDB single table · S3
- Infrastructure
- AWS CDK (TypeScript) · CloudFront · EC2 t4g.nano · VPC origin + IPv6 egress · EventBridge Scheduler · SSM Session Manager
- Tooling
- pnpm workspaces · Turborepo · Biome · Vitest · GitHub Actions (OIDC) · gitleaks + secretlint
Architecture decisions
Each significant choice is written down as an ADR: context, decision and consequences.
- ADR-0001One stateful real-time server instead of serverless WebSocketsAccepted
- ADR-0002uWebSockets.js for the real-time gatewayAccepted
- ADR-0003Binary hot path + spatial-grid interest managementAccepted
- ADR-0004DynamoDB single-table designAccepted
- ADR-0005Private origin via CloudFront VPC origin, IPv6 egress, no NAT or public IPv4Accepted
- ADR-0006Static export (Next.js) instead of server-side renderingAccepted
- ADR-0007EC2 t4g.nano with standard CPU credits as a hard cost ceilingAccepted
- ADR-0008Ship releases through S3 + SSM. The server never talks to GitHubAccepted
- ADR-0009Client-authoritative movement, validated by the serverAccepted
- ADR-0010Each visitor's own sky, from the edge's city-level locationAccepted
- ADR-0011The real-time server keeps serving through a storage outageAccepted
- ADR-0012The owner's identity, from a passkey and a signed cookieAccepted