Building a Minecraft Server Status Checker with Next.js 15 and Server-Sent Events
I recently needed to add a real-time server status checker to Minecraft ServerHub (https://minecraft-serverhub.com) — a server list with 1,000+ Minecraft servers. Instead of polling, I used Server-Sent Events (SSE) to stream results as they arrive.
Why SSE Instead of Polling?
Polling with setInterval hits your API every few seconds. With 1,000 concurrent users that's 1,000 requests/second, the UI flickers between states, and you pay for calls even when nothing changed. SSE opens one persistent HTTP connection — the server pushes updates the moment they're ready.
The Minecraft TCP Ping Protocol
Minecraft Java Edition uses a custom binary TCP protocol — not HTTP. You open a raw socket to port 25565 and exchange packets using VarInts (7 bits data + 1 continuation bit per byte). Two packets needed: a Handshake declaring your protocol version, then a Status Request. The server replies with JSON containing player counts, version, and MOTD.
The Next.js 15 SSE API Route
The route runs on Node.js runtime (required for raw TCP) and returns a ReadableStream with Content-Type: text/event-stream. It streams three events progressively: "connecting" immediately, "checking" after a cache miss, then "result" or "error". The UI stays responsive even for servers with a 5-second timeout.
Redis Caching
Each successful ping is cached in Redis for 60 seconds. Cache hits return instantly with a cached: true flag. This reduces raw TCP connections from thousands per minute to a handful — essential when you have 1,000+ servers being checked simultaneously.
Why SSE Beats WebSockets Here
SSE is unidirectional (server to client only) — exactly what a status checker needs. It works over standard HTTP, has built-in browser reconnection, and uses standard auth (cookies, headers work identically to regular requests). WebSockets are overkill here — save them for bidirectional apps like chat or multiplayer games.
The Live Result
The finished checker is live at https://minecraft-serverhub.com/tools/server-status-checker — Java and Bedrock support, real-time MOTD rendering with color codes, player counts, version info, and latency.
A free REST API (no key required) is also available at https://minecraft-serverhub.com/developers — useful if you want to embed server status in your own site or Discord bot.
Questions about the binary protocol or SSE implementation? Drop them in the comments!