 Hi everyone, thanks for taking some time in your morning to attend this talk So I'm going to talk about Maybe that way I'm here to talk about the challenges and secrets of the real-time world like Real-time applications, real-time infrastructure, all the things that Allow you to create real-time apps So I am Martin Lagrange I am a software engineer Work at Pobnab, a real-time desktop network You can find me. I'm SuperTinu on Twitter. I'm SuperTinu on GitHub This DM of this presentation is to Yeah, to be as simple as possible I didn't want to go much into the details, but we'll tackle the main things So first of all, I would like to show you a short video that gives you a bit of context about What are the real-time apps? So I just suggest examples of real-time apps, Periscope just right-sharing applications games IoT and Remote control, all this stuff are real-time applications and When you talk about real-time apps, it means real-time data So if it's a right-sharing app, messaging app, trading apps will be different kind of data and in order to To share this data and have this data come coming back and forth between the device or clients you need a protocol and For that you need a real-time protocol and What is the real-time protocol actually? Real-time protocol is a protocol that allow you to have Always own connection Which is very directional fast and which is supported everywhere and that's all we need to to do real-time applications So people would think okay. Yeah, well, I will do so much to build a city people in to add some real-time feature in my app Yeah, I will pull my my server every once a month. It's got to be right But yeah, it's not gonna be real-time. It's not gonna be efficient. It's not gonna be on always own no scolable and so on So there are a lot of protocols out there. I should be streaming web socket Kafka and QTT long-balling servers and even so get the tile web socket all this and What are What might make them different and what's the best protocol It's kind of a hard question. It's kind of tough question to answer actually all the Different main real-time apps like Facebook Messenger Facebook itself Slack Huber WhatsApp all this when you think about this main Companies that are using real-time Features intensively. They are all using different protocol XMPP Kafka HG belong polling web socket and so on and What makes them different? so actually they all work on top of TCP and so You may be remember these Aussie layers you have TCP on the natural layer and the application layer with all the protocols and which are all working on top of TCP and so they are all sending TCP packets At the end of the day the other three sockets Let's see P packets to see P packets So when you initiate a Real-time communication we have a server what are the steps that are needed to be done? So first of all you need to do a DNS lookup to get the address of the server so you did you do the DNS lookup you View via the utp Poor protocol and you get an IP of a server and then the server You will reach a server and you share the TCP socket for a TCP socket connection You will need to do a TCP handshake TLS handshake and finally the request So exchange Round trip of TCP so TCP packets so what makes the What makes a TCP connection Real-time what makes it different than other protocols like HTTP or a basic row HTTP or Pop-free or any other protocols is that this Both the clients and both the servers will understand each other. They need to keep this TCP socket open And that's for all the different protocols. That's the same thing Is that the client and the server keeps the the TCP socket open? So that once the TCP socket is open then you they exchange TCP packets and most of the time the server will send just push some TC Some data to to the clients So I like to talk about HTTP long-balling so Facebook uses it so it works well, but it's kind of tricky because What happens with this piece of cut if you look at if you inspect your network calls from the Google Developer tools is that you open the XHR? tabs by the way If you just like the tips you want to inspect you can also use the web socket tabs and you can see you can see what? What are technologies are used? What technologies are used for real-time features? So you for Facebook you will see a lot of different Request that are made against the server and they typically pulling out works is that it's open a connection And then it keeps it open and then when the data is available from the server it will Stop the connection and give you all the data available and then the clients needs to reconnect again And again to fetch the data so it's it's could be considered as a hack But it works well, but so what is tricky is that you would think maybe so there is always like connection made against the server So you would think okay? So the TCP sockets needs to be initiated all the time. I need to do the next lookup it's going to introduce a lot of latency and It's good. You're going to need to do tpNshake, tlsNshake and all this stuff but actually since HTTP introduced the keep alive feature is your TCP socket is going to be reused for the next connections and You will think that you have different Request and different cpsockets, but it will be the same cpsocket So there is one thing with HTTP long polling is that it uses HTTP so it introduced a lot a bit of overhead because The headers are really heavy compared to other protocols which are more lightweight and One thing is if the connection Drops you will need to reconnect again For all protocols is the same you need to do the same thing again and we initiate the tip cpsocket So I like to I wanted to show you and there are kind of another Microsoft What makes the pros different and we will we saw that it's not that different Many depends on the the packets Exchange when the request is the tpsocket is initiated So people will think okay, yeah use web socket use XMVP, but Just the protocols is not sufficient enough. You need a server infrastructure behind behind the scenes to Make all these things happen So how it works in a another hood is all the Clients who's gonna connect against the server gonna open connection and the server is gonna work as a hub and yet Distribute all the different messages to the to the different clients which are subscribing to the concept of Channels or topic so how it works Most of time you have like this Concept of channel or topics and you can subscribe to different channels and the server is gonna register your Your clients so that when your client is subscribing to one channel if there's other clients publishing they gonna They're gonna push this data to to the open connections and Scaling is a really really huge challenge for the real-time real-time service So you need to select which house you're gonna send it to the connections to you need to To make sure that all the clients Publishes the data to one house will have the data label to to the to the clients subscribing to a different host and Amongst different servers and you need to to scale originally among different CPUs and and Vertically and originally and it's all it's a big challenge one other challenge is This feature called multiplexing because you want to avoid different TCP connection against a Server when you want to fetch data from different channels And in order to do that you need yet to need to have like a sort of Feature that allows you to to receive this data Yeah You need to allow you to subscribe to different channels and yeah push data Give you gives you a cue that is unique to your your subscription So just here is an apple of one Client subscribe to two channels and the server will forward the messages There is another challenge is When you lost internet connectivity, so you may think yeah, it's not an issue, but It's more common than you would think that to lost internet connectivity and Your app can be really sensitive to internet Internet connectivity issues and so when your connection is lost then you need to you will miss the messages that are published between the time That you are not online and in order to prevent that you can have a kind of a catch up feature that is not out of the box for all the all the All the apps all the frameworks that will allow you to kind of resubscribe when your your your connection drops with a timestamp or time stamp or a Sequence ID to to allow you to Resubscribe and get all the miss messages that you lost another challenge That you wouldn't think is what about if my users are everywhere in the world You maybe don't see the what is the challenge here is that if you have a Client in Japan if you have a client in Brazil, and if you have a client in the UK They let's say the the client because the client in the UK publish a message and subscribe message into and the island you need to Like the users in Japan and Brazil It is going to be a long it's going to introduce a lot of latency to connect directly to the To the server in Ireland, so you may are maybe familiar or not. We've the concept of CDN content delivery network, so That what allows you CDN is to have the data cached in different servers in the world so that Depending on the location of the the user it will it will connect to the closest data center to him and What is the challenge here is that it's different with real-time data is that you The data is always Renewed and it's always is you can't get a cash is data is always new new data So what you can do instead it's which is more faster is to have when a user publish a message and subscribe to a message You can have this data replicated to different servers in the world To allow you to have all the users subscribing to their own servers Which is closest to their location and it's it's it's you would think it's it's it's You would you would be surprised, but it's faster to duplicate his data amongst the different data center servers And have this user connects to the closest data center So how it works it's works with the concept of geo DNS that will Allows you to With the concept of DNS sub subnet information that the the client will Provide when he did the DNS look-up request the DNS server will be able to get the location the Public IP of the customer and knows where he should Which IP which server he should Gives in back to the to the DNS look-up request so that the the client because to the client Connect to the closest So as a summary, I will say real-time is awesome The protocols are not that different and the protocol is not the only things that matters. KB is a big challenge with regarding real-time framework and servers multiplexing is Something that you may need to have which is not out of the box and also have a policy for in the Recreation very issues and a geo redundancy. So you have a full like you have your app, which is Really fast for a different user in the world and anywhere Thank you very much for your attention To thank you. I have some gifts for you. I printed out a Call it's called a zine from Julia Evans, which is really cool about network in hack So I have it with me. I only I have like kind of 50 copies. So if anybody wants out Just feel free to to get it's really neat Yeah, if you have any questions, let me know Yeah Yeah, so the question is if the replication thing that I mentioned earlier to replicate different between different servers Is there something that helps you out for this and There are no post in celebrity or not. And the question is I As far as I see so I Yeah, you can be all yourself, but I'm not aware of yeah open source things or Yeah, that will or even like the document on the Internet that will Help you with that Easy answer Yeah, please Will the wonders of HTTP version to help you in this? Yes, a good question. So the question is if what what about HTTP to will you would helps you With this so you can maybe Think about HTTP to and long polling So HTTP to introduce a feature called server push You would think it will help you on that, but actually it's It's not a server push regarding data like Web so get like a Data coming to your brother. It's more about Assets so you can't get this data. It's it's not something I just want to mention it's not This feature called server push is not something that will suit with what in HTTP to introduce as well is to use So you can have different you can use one connection and have different Different Different requests in the same connection. So, yeah, I I don't I don't know what to answer. I was thinking in the same time But yeah, I Out of I don't think it would let's let's maybe more let's read about that Yeah Is able to handle efficiently a multiple games What what what do you mean by my I would say it depends so there are pros that are most suitable for that so Web sockets are definitely something that I mean other pros that have less Overhead in the in the package that I exchanged between the the server and the clients are more suitable for that Because yeah, you want you want the less information sent but Yeah Definitely will help you it will be suitable for that Thank you