I’m building a small Go HTTP service with PostgreSQL. Most requests are synchronous, but I’m starting to add work that doesn’t need to finish before returning a response: sending notifications, processing uploads, and similar tasks.

My current thought is to run those jobs in a small in-process worker pool and use a root context created with signal.NotifyContext for shutdown. When the service receives SIGTERM, it would stop accepting new work, wait for active jobs for a limited time, and then exit.

The part I’m unsure about is where people draw the line. At what point do you stop using goroutines and channels inside the API process and move jobs to a durable queue or a separate worker?

I’m especially interested in approaches that have worked well for small services before the infrastructure becomes unnecessarily complicated.

submitted by /u/SatyrCode
[link] [留言]