Menu

Post image 1
Post image 2
1 / 2
0

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

DEV Community·Abhishek Sharma·about 1 month ago
#mOsojEMr
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.

Read More