Question

I'm trying to wrap my head around a Queue system. I have read many resources about it but I keep ghosted with this question.

If I have listeners that loops over a collection of users, to send a notification via FCM or APNS or Pusher or SocketIO, etc, for each one of them, and the Event which triggers the listener were be able to be called by anyone at anytime, which one should I queue? The Listener? or the Notification? or both?

Most of them are only explaining the essence of how they works and how they're implemented, I understand the concept, but not about what to queue, when and why it should be queued. Though, I still learning, and I would like to know more about queueing in practice.

Was it helpful?

Solution

Queues decouple spacetime.

When you want to do something not now, use a queue.

  • You now write to a queue.
  • You later read from a queue.

Where you want to do something not here, use a queue.

  • You here write to a queue.
  • You there read from a queue.

Events and notifications are both a natural fit for queues. They are a message from the past (usually very recent past) from somewhere, that is usually needed to be understood here, and now. Or are a message written here and now, that somewhere, and some when needs to be understood.

Whether or not you use a queue for either of these depends entirely on when and where. Here and now it is a value/variable in your function. Otherwise it is a value to be received from a queue, or to be sent on a queue.

Licensed under: CC-BY-SA with attribution
scroll top