2

Since golang handles incoming requests in separate goroutines, it's unclear to me which types of tasks should be deferred for processing by a message queue e.g. NSQ consumers and which should be handled within the http request goroutine.

paulkon
  • 1,587
  • 2
  • 18
  • 32

1 Answers1

2

Since the net/http package runs each request you do not need to worry about blocking the request goroutine. The real question you should ask myself is "Do I need to do this before I return a response to the client, or can it be deferred until later". Generally if I need to fetch from a database to serve a response that will block the request goroutine, and that is ok. If I can return a response now and put a message on a queue to do stuff later, that can be ok too.

Since the request goroutine has little cost to exist, and it is isolated from other requests, you really don't need to worry about it that much. Do what makes sense for the client.

captncraig
  • 19,430
  • 11
  • 95
  • 139