Shishir Pai

mining network in under two sleepless weeks

building midnight's power-user miner + serverless backend end to end in under two weeks

· 3 min read · distributed systems, systems

nocturne []

midnight ran a limited token distribution called scavenger mine. mine the most in a ~20 day window, get the most of the drop. the official way in was a browser tab. connect a wallet, give it a few threads, submit solutions. accessible, and useless if you actually wanted to compete. power users wanted real servers, every core, multiple wallets, something that behaved like infrastructure instead of twenty tabs they were scared to close.

so the opening was obvious. build the miner regular people couldn't, and capture the users and their revenue before someone else did. i built it end to end in under two weeks with @nkz, as a full-time undergrad, in stretches of nearly 18 hour days. i led the core miner and backend development while skipping lectures.

the client is a multithreaded miner in rust, the part that has to be fast. the backend is where the actual systems problem lived, because it had to survive tens of thousands of machines hammering it at once with basically no ops headroom.

14,000+ machines │ challenge? / here's a solution ▼ Cloudflare Workers (stateless, TypeScript/Hono) │ Hyperdrive ──connection pool──▶ Postgres │ KV ◀── hot state / rate limits

1 dot ≈ 20 machines (700 dots). 1 moving dot ≈ 10 requests, at the 11 day average of ~350 a second. the KV / Postgres split, the workers and the pool connections are illustrative. select a stage to light its stream.

1 dot ≈ 40 machines (350 dots). 1 moving dot ≈ 10 requests, at the 11 day average of ~350 a second. the KV / Postgres split, the workers and the pool connections are illustrative. select a stage to light its stream.

the whole backend is stateless by design. no machine holds session state, so it scales horizontally by default and cloudflare just runs more of it. that one choice is why 14k machines didn't turn into a coordination nightmare.

it was never cpu. it was high-concurrency Postgres writes. every verified solution is a write, and 25 million of them landed over eleven days. opening a fresh db connection per request from the edge would have melted the database instantly and I learned this the hard way.

initially everything was fine, because traffic was low enough for the mistake to stay hidden. then volume picked up and on supabase i kept seeing db CPU usage peaking. i upgraded several times in panic with it only being sustainable for mere hours each time. after i realized i can't afford the hourly costs, i did some digging. my query optimizations were pointless, but then it hit me. cloudflare workers are ephemeral. each time they were invoked, postgres connected via a direct db connection string. i had used this string as if the backend were a traditional server which only held a single long running connection. With workers, there were hundreds or thousands of connections behind held constantly with every read or write clients made.

hyperdrived saved me. this sits in front of postgres and pools connections, so thousands of concurrent workers share a small warm set of connections instead of choking the db.

i could keep on going about the architecture but the codebase will remain private and i don't want someone to copy this into claude code.

  • 331 million requests in 11 days
  • 25 million cryptographic solutions verified
  • 14,000+ active machines, 50,000+ client downloads
  • 328 MH/s peak network hashrate (~36,000 M4 Macs' worth)
  • zero downtime, except one Cloudflare outage i didn't cause

the community mined more than $6M in tokens through it.

[back to writing]