Real-time data streaming using Python and Web Sockets & also its integration with MongoDB

Akash Tikkiwal
3 min readMay 13, 2021

--

We have several options for real-time data streaming in web applications. We can use polling, long-polling, Server-Sent Events and Web Sockets. The last two can be used for server-push scenarios where we want to send data to a browser without any specific request from the client. All of this solutions have their advantages and disadvantages, so we need to make sure that a particular approach is the best for our application.

Why use Web Sockets?

A Web Socket connection allows full-duplex communication between a client and server so that either side can push data to the other through an established connection. The reason why Web Sockets, along with the related technologies of Server-sent Events (SSE) and WebRTC data channels, are important is that HTTP is not meant for keeping open a connection for the server to frequently push data to a web browser.

PROJECT DESCRIPTION :-

So for this type of project, I have used socket programming in python to create a real time data streaming socket which will help me to create a server socket(where I will receive data) and the client socket(from where I will send data). And the data can be in any form like it’s just a packet we are sending from the client to the server so the data can be text, command or in any other form. Here instead of working in my local windows , I have used redhat linux Os because my requirement is to do some additional tasks & I will run my code for server socket from linux OS only. For client socket, I created the code for it in my windows , here in my case I have used jupyter notebook to write my code for client socket.

Then I also integrated this kind of infrastructure with MongoDB , so that if my requirement is to send some data to the MongoDB server, I can sent it through my web socket only and that database and collection can be deployed to the MongoDB.

WHAT IS MONGODB?

MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.

Companies and development teams of all sizes use MongoDB because: The document data model is a powerful way to store and retrieve data that allows developers to move fast. MongoDB’s horizontal, scale-out architecture can support huge volumes of both data and traffic.

You can see the whole infrastructure automated in the video that I have already posted on Linkedin.

Thanks for reading !! :-)

--

--

No responses yet