Hacker News–style demo app hosted on Cloudflare Workers, with PlanetScale via Hyperdrive. Local development runs entirely in Docker, including a local MySQL 8 container. Schema and VSchema are shard-ready to colocate each story with its comments.
- Docker and Docker Compose
-
Copy env example and adjust if needed:
cp .env.example .env
-
Start containers (app + mysql):
docker compose up --build
The app listens on http://localhost:8787.
-
Initialize schema:
curl -X POST -H "Authorization: Bearer ${ADMIN_TOKEN:-devtoken}" http://localhost:8787/admin/migrate -
Generate fake data:
curl -X POST -H "Authorization: Bearer ${ADMIN_TOKEN:-devtoken}" \ -H "Content-Type: application/json" \ -d '{"users":50,"stories":50,"commentsPerStory":10}' \ http://localhost:8787/admin/loadgen
-
Browse:
/top stories/item/:idstory detail with comments
- Set
DEV_MODE=workers(in.envor your shell) and ensure you have a Hyperdrive binding namedHYPERDRIVEconfigured in your Cloudflare account pointing to a PlanetScale branch. - The app inside Docker runs
wrangler dev --remoteand uses the Hyperdrive connection string.
vschema-slacker-news.jsondefines the unsharded keyspace with:items_seqmarked as a Vitess sequence table- Standard tables:
items,users,votes
vschema-slacker-news-sharded.jsondefines the sharded keyspace with:itemsandvotessharded byroot_id(hash vindex) for comment colocationitemsconfigured withauto_incrementreferencingslacker_news.items_sequsersas a reference table (replicated to all shards)
- ID generation uses Vitess sequences (the proper Vitess-native approach):
- Sequence table
items_seqprovides monotonically increasing IDs - Works identically in unsharded and sharded modes
- Stories pre-fetch ID from sequence, then INSERT with
root_id=idset correctly - Comments inherit
root_idfrom parent story for shard colocation
- Sequence table
- The Hyperdrive connection uses
database: "@primary"to enable automatic routing to the correct keyspace (sharded or unsharded)
npm run dev:local— start Node server against local MySQL (Docker)npm run dev:workers— run Workers dev (remote) against Hyperdrivenpm run deploy— deploy Worker
.envcontrols local MySQL andADMIN_TOKENused for admin endpoints in local mode..dev.varscan be used if you prefer Worker dev secrets; not required for local mode.
- No additional services are installed on your machine; everything runs inside Docker.
- Dependencies kept minimal:
hono,mysql2, and dev-only@hono/node-server.