Menu

Post image 1
Post image 2
1 / 2
0

I Needed to Send an HTTP Request Without Slowing Down My API. Goroutines Fixed That.

DEV Community·Abhishek Sharma·28 days ago
#vp0rxOjq
#go#goroutines#backend#fullscreen#worker#part
Reading 0:00
15s threshold

In Part 12 , I added resilience patterns — retry, timeout, circuit breaker. My backend could now survive Redis going down. But there was still a problem. When someone created an entry, I needed to notify an external service. A webhook: fire an HTTP POST, tell the world something happened. I added it inline in the handler: func CreateEntry ( w http . ResponseWriter , r * http . Request ) { // ... validate, save to DB ... webhook . Send ( url , payload ) // 🐌 blocks here respondJSON ( w , http . StatusCreated , ... ) } Enter fullscreen mode Exit fullscreen mode The user waited. Not for their entry to save — that was fast. They waited for my HTTP request to some external service to complete. If that service was slow, every create request was slow. If it was down, every create request failed. The handler shouldn't care whether the webhook delivery succeeded. The entry was saved. That's the job. Everything else is secondary. I needed fire-and-forget.…

Continue reading — create a free account

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

Read More