Repository pattern & pooling

*sql.DB is a pool, not a connection

One idea reshapes how you use database/sql: a sql.DB is not a single connection β€” it's a pool of connections that Go manages for you. It's safe to share across goroutines, so you open it once at startup and hand the same sql.DB to everything that touches the database.

You do not open a new *sql.DB per request. Each Query/Exec borrows a connection from the pool, uses it, and returns it. That's what lets one Go server handle thousands of concurrent requests against a handful of real database connections.