Skip to content

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.

Architecture of kenilgor.comThe browser reaches CloudFront. CloudFront routes static pages to S3, API calls to Lambda and WebSockets through a VPC origin to an EC2 t4g.nano running Node.js and uWebSockets.js. Lambda and the server store data in DynamoDB; the server also writes to S3. EventBridge Scheduler runs scheduled Lambdas.BrowserNext.js static site3D world (lazy-loaded chunk)HTTPS + WSS, one domainCloudFrontHTTP/3 · Brotli · security headers/*/api/*/rt (WebSocket)S3 site bucketprivate, origin access controlstatic pages + hashed assetsLambda Function URLsarm64 · Node.js 24contact · garden · statsEC2 t4g.nanoprivate subnet, no public IPNode.js + uWebSockets.jsreached via CloudFront VPC originDynamoDBsingle table, on-demandS3 data bucketsnapshots · ghosts · releasesEventBridge Scheduleruptime probe, nightly jobs
/* → 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

  1. 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.

  2. 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.

  3. 03

    Shard the world

    World layers are capped at 100 players and created automatically. Presence counts stay global.

  4. 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.

  5. 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.

  6. 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.

Estimated monthly AWS cost
Item$/month
EC2 t4g.nano on-demand2.04
EBS gp3 8 GB0.73
Route 53 hosted zone0.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 origin0
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