How to Implement Database Connection Pooling Best Practices in Go

Reuse a single http.Transport instance with configured MaxIdleConns and IdleConnTimeout to implement efficient database-like connection pooling in Go.

Reuse a single http.Transport instance across your application and configure its pooling fields to manage connection limits and timeouts.

var client = &http.Client{
	Transport: &http.Transport{
		MaxIdleConns:        100,
		MaxIdleConnsPerHost: 2,
		IdleConnTimeout:     90 * time.Second,
		DisableKeepAlives:   false,
	},
}

This setup ensures connections are cached and reused efficiently, preventing resource exhaustion under load.