Menu

1 / 2

My Backend Crashed Every Time Redis Went Down. Three Patterns Fixed That.

DEV Community·Abhishek Sharma·6 months ago
#mOsojEMr
#pattern#problem#go#resilience#redis
Reading 0:00
15s threshold

In Part 11 , I built a metrics system to see the big picture — request counts, latencies, error rates per endpoint.

Then I looked at my main.go and realized something embarrassing. The JWT secret was hardcoded. The Redis address was a string literal. The rate limit was a magic number buried in middleware. Every config value was scattered across different files with no central source of truth.

And then Redis went down during a test, and my entire backend froze. Every request hung for 5 seconds waiting for a timeout. The server was technically running but completely useless.

Two problems. One week.

Problem 1: Config Values Everywhere

My main.go looked like this:

err = db . InitDB ( "./data.db" ) err = redis . InitRedis ( "localhost:6379" )

// Somewhere in a handler file: secret := os . Getenv ( "JWT_SECRET" )

// Somewhere in middleware: maxRequests := 100 window := 60 * time . Second

Enter fullscreen mode

Exit fullscreen mode

Four files. Four different patterns for reading config.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.