Sitemap
Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Member-only story

Stop Spawning Infinite Goroutines: Use Tee-Channels in Go for Scalable Event Handling

--

Press enter or click to view image in full size

Imagine you’re working on an app that allows users to sign up for free. But you also want to make sure that someone from the sales team follows up to nudge the user to subscribe. So you have two tasks after the user is successfully signed up:

  1. Send a welcome email to the user.
  2. Notify the sales team on Slack.

Naturally, your first version looks something like this:

  • User signs up
  • You send a welcome email
  • Once that’s successful, you notify the sales team

Sounds clean.

But here’s the thing — you’ve now tied the success of the sales notification to the welcome email, which is not just a coupling nightmare, it’s also a recipe for “Oops, we never told the sales team.”

⚠️ The Goroutine Trap: Scaling Gone Wild

So you think, “Let’s parallelise it! Fire two goroutines!”
Great. Until…

You host a workshop, and suddenly, a hundred thousand users are signing up.

Now your server is firing two goroutines per user and context switching like it’s in a dance battle. CPU usage spikes, latency…

--

--

Archit Agarwal
Archit Agarwal

Written by Archit Agarwal

PMTS @ Oracle | Golang | Docker | Kubernetes| Typescript | Node.js | .NET | Angular | AWS Certified Cloud Practitioner | Educator