Thursday, 26 March 2020

Reddis , RabitMQ , celery , mongoDB -- confusing world for a newbie


So, if you have searched something for distributed task queue, or asynchronous task or even "how to send email from Django" you would have encountered above words in title.

Yes, they can do your job. really.

But do you need all of them to do your Job (like sending email from Django)?? No.

Even with just Reddis , RabitMQ or mongoDB you can achieve that. (celery always need a message broker i.e someone to command the task and then celery can do rest of the thing. ).

So , What are all these things ????

First let's understand Reddis vs MongoDB.

Well both are NoSQL database.But there are some key differences between them , which makes them chamipion of their domain:

1) Reddis is an "In-memory" "NoSQL" "Key-Value Store/Database" with some capability of a "Message queue".

"In-memory" means it is stored in RAM by default , that is why it is very fast , useful when your data beign updated at very high-speed for example if you want to store stock market data and do some runtime analysis on them.
But with reddis your data base size will be limited by the RAM you have availible.

It can be also used as "Message queue" and that is why it is compared many times with RabitMQ. you will find many questions regarding this on stack overflow.

2 ) MongoDB is "by default stored on disk" , "NoSQL" , "document store/Database" , with no official "Message queue" stuff.

Disk based means database will be stored in your SSD or Hard disk.
Although it will make it slow, but there are many comparison article which says mongoDB is at par with Reddis in terms of speed.

But wait , from mongoDB 3.6 onwards , mongoDB supports change streams. By using change streams you can implement similar functionality like message queue, interested ??
Read this article :

https://api.mongodb.com/python/current/api/pymongo/change_stream.html >

All clear upto this ???


3) RabitMQ is a distributed message queue, and it is not a full-fledged database.

Message queue is needed when you have one or more producer of tasks and you want them to be consumed by consumer in a distributed manner, and you don't want to take tension.
you can read more about rabitMQ on their official site. just search like rabitMQ python tutorial.


4) So what's celery??

Celery is something if you combine with rabitMQ , than it can even further reduce your tension.
Celery also supports reddis, but believe me you should be focusing RabitMQ + celery stuff.


So, that's it people. I know you might not be enhancing your knowledge much from this dumb article, but this is what I wanted to document.

Websockets Vs Sockets - a simple explanation


Note : TCP/IP is a different stack and a practical version of OSI model . It doesn't implement all layers of OSI models.

Read this article on geeksforgeeks : < https://www.geeksforgeeks.org/tcp-ip-model/ >.
I was able to recollect all my readings in below image :


Some plain simple examples where sockets are used is real time chat , cricket scores , stock market data etc.
If you see something changing on page being changed without page reloading it could be web socket , although there are many other technologies like AJAX.

Important points to consider :

1) Plain sockets are based on TCP/IP , they are often called TCP/IP socket. Both sockets have same purpose allow stream of data without continuous hand shaking.

2) Websockets were designed as web browsers didn't had support for TCP/IP socket , as most of the webbrower as you know work on application layer.

3) Today many browsers support web sockets , however now there are many non-browser based clients exists for web-sockets.

Important : You may not need websocket all the time . websockets have additional overhead compared to sockets , so you might consider TCP/IP sockets if you are working in non-browser environment.

Also , the new buzz is socket.io , if you would like to read about it let me know.