I’m trying to understand ways to accomplish things using patterns that would be familiar to other Django developers.
In this case, I have a requirement to capture information tangentially related to the request.
This information will not be shown to the user. Instead, it will be used to help us identify areas our service to improve. You could think of it as performance metrics for critical pieces of our code. The data we want cuts across our domain in several places.
Since it’s tangentially related to our domain, I’d like to segregate the code that handles this data away from the business logic.
My first thought would be to create some kind of message bus, but I haven’t seen a pattern like that in the Django community.
Is there something in the Django ecosystem that I’m missing? How would you implement this feature?
I can think of at least two ways to implement it.
Django Channels. You can define “groups” and have different worker processes join groups as necessary to receive messages. (That is one of the mechanisms that we’re using to achieve this type of functionality.)
Celery. Your process that needs to notify the external processes does so by initiating a celery task.
Personally, I’ve become a lot more fond of the Django Channels architecture - but then it suits our requirements perfectly, and the potential downfalls are not a concern for us.
Channels is an “at-most-once” delivery method, where Celery with RabbitMQ is “only once”. This means that there is the theoretical possibility of messages being lost, but (a) we’ve never seen it happen and (b) even if it did happen, it wouldn’t materially affect the application. (This is not accounting for situations where one or more components are down, but that’s a different issue.)