[Django Channels] Private Chat Advise

I’m developing a mobile application with Django as a web api.
Recently the client requested to add private chat feature. The problem is that I don’t want to add more technologies to my stack.

My question is , can I use Django Channels for private messaging (one-to-one) and ensure reliability at the same time.

Is Django Channels taking into account private messaging and have the ability handle it smoothly.
If the answer is positive , how can we achieve that.

Note that I’m using the latest version of Django V3

Hi Haidar,

Yes Channels can do that. The channels tutorial gives chat as an example: https://channels.readthedocs.io/en/latest/tutorial/index.html . Although it’s chat rooms, you’d really want to use a connection per user to send them the messages DM’d to them.

To make messages reliable, you’ll want to store them in the database. This is also probably the case if you want users to be able to see past messages when they reopen the website. Websockets can then be seen as a way of speeding up delivery compared to HTTP polling.

Using Channels with Django 3.0’s ASGI handler might not be the easiest right now as Channels isn’t on ASGI 3 but that’s being worked on and there are workaorunds.

Hope that helps,


1 Like

Instead of sending a message to a group, you can send to a channel.
More info here: Channel Layers — Channels 3.0.3 documentation

1 Like