Deploying a chatbot with Django: WebSockets vs HTTP

329 views
Skip to first unread message

Mukul Mantosh

unread,
Feb 16, 2019, 12:32:03 AM2/16/19
to Django users

I currently have a chatbot app in my django project that I would like to deploy.


I am confused as to whether I should use WebSockets or normal HTTP calls (AJAX) for it's implementation. This is what I have understood about the pros/cons of each(in the context of my use-case) till now after some internet research.

Reasons for using WebSockets over HTTP:

  1. WebSockets are recommended for chat applications because of low overhead per user message once the connection has been established. HTTP will have the overhead of establishing a connection each time a message is sent (Also the header will be bigger in size, which will be sent with each request/user message)
  2. WebSockets allow for real-time communication without workarounds like polling in case of HTTP which can lead to many unnecessary requests from the client.

Reasons for using HTTP over WebSockets:

  1. HTTP just might be okay for a chatbot(not human to human chat) because the response of the chatbot is only triggered when the user messages something i.e. The Bot isn't expected to message the user all of a sudden at random intervals which would require real-time communication. The Bot only sends replies to user messages.
  2. Will have to use django-channels and an ASGI server for the chatbot part, which will require maintaining two servers (along with WSGI), which will make the implementation a little bit complicated.

What should I go ahead with?

P.S. Someone suggested I look into services like Pusher, although it doesn't seem to have server side SDK for python

Reply all
Reply to author
Forward
0 new messages