Database Strategy Guide: Proxy Server and Hyperdrive
This guide helps you choose the right MySQL connection strategy for your ZinTrust application on Cloudflare Workers. Since Workers are stateless and often run in many regions, connecting to a centralized SQL database requires careful architectural choices.
Option 1: Node.js Proxy Server (MySqlProxyServer)
Architecture: ZinTrust runs a lightweight Node.js HTTP server (typically on a VPS, EC2, or container) that sits next to your database. Your Cloudflare Workers send SQL queries to this proxy over HTTP, and the proxy executes them against the database using a persistent connection pool.
| Feature | Details |
|---|---|
| Speed | Fast & Consistent. The proxy maintains a warm connection pool (mysql2), so queries execute immediately without waiting for a TCP handshake. |
| Load Handling | High. Can handle thousands of concurrent Edge requests by multiplexing them over a fixed number of DB connections. Serves as a connection buffer. |
| I/O Limitations | None. Runs in a standard Node.js environment. No "cross-request I/O" errors. |
| Operational Overhead | Medium. Requires hosting and managing a separate Node.js process (e.g., via PM2 or Docker). |
| Security | Supports signed requests (HMAC) to ensure only your Workers can talk to it. |
Best For:
- High-traffic production applications.
- Teams who can host a small Node.js service (e.g., $5 VPS or existing container cluster).
- Scenarios requiring maximum throughput and low latency.
Summary Recommendation
| Priority | Recommended Strategy |
|---|---|
| Performance & Scale | Use Option 1 (Proxy Server). It is battle-tested, standard, and robust. |
| Convenience (Zero Ops) | Use Cloudflare Hyperdrive (managed service) for managed pooling without maintaining a proxy process. |
| Local / Development | Start with proxy mode locally to keep behavior aligned with production. |