If you want to add realtime functionality to your web or mobile app, you may have considered using the WebSockets protocol to push data between the server and the client’. In our “What are WebSockets?” blog post published last week, we looked at what WebSockets are and why you might use them.
In the video below, Stephen and Ian briefly discuss how PubNub can be used to enhance your WebSockets application. Or keep reading the blog post below for more detail.
The WebSockets protocol is exactly what its name implies – a protocol. It establishes a grammar between two systems utilizing the well-established and loved TCP layer. When implemented, it communicates over a persistent connection between server and client. And then, you’re on your own. So, what’s next? What do you actually need to deliver realtime in your apps?
Establishing a connection to each device is only the beginning. Now, you need to do something with that persistent connection. This is where PubNub comes in. PubNub provides a set of realtime “building blocks”; services that take advantage of an open socket connection.
- Publish / Subscribe — PubNub provides an easy way to Publish realtime data, either individual devices or large groups of them.
- Presence — PubNub gives you realtime visibility on who is subscribed on a “channel”, so you know who’s connected and who’s gone away.
- Storage / Playback — PubNub records data streams and provides instant access and queries into data that was published in the past.
- Analytics — You get realtime and after-the-fact views on realtime traffic and usage.
- Cross Platform — Publish complex objects that get automatically encrypted, serialized, and delivered to the subscribers within 0.25 seconds, and automatically deserialized and decrypted (even across different programming languages and platforms).
- Security — PubNub adds AES encryption to realtime, as well as a full grant/revoke framework to ensure only authorized users can subscribe to realtime data streams.
These are a few examples of a rich set of building block services that take advantage of persistent socket connections made possible by WebSockets and other realtime protocols. And while there are several libraries and frameworks that also provide various realtime features using WebSockets, like Socket.IO, SignalR and SocksJS, none of these frameworks scale out-of-the-box. And deployment and scaling is where the pain really hits.
Realtime Deployment for WebSockets Apps
As complex as it is, getting realtime functionality developed is only 25% of the challenge. When you start dealing with high traffic, operational and scaling challenges kick in. Deploying and scaling a reliable realtime system involves a complex set of operations and orchestration hurdles. Over time, over 75% of your time and budget will end up focused on scaling and maintaining a self-hosted realtime system.
Supporting a successful app in a production environment requires many redundant servers, new kinds of monitoring tools, sophisticated deployment and failover processes, engineering maintenance and upkeep. Maintaining a realtime data stream network with redundancy, geographic server distribution, geo-routing, latency monitoring, and high reliability is hefty financial burden. App companies that support their own realtime systems often find themselves spending over half their engineering effort building and maintaining the realtime infrastructure instead of focusing on improving their app’s value proposition. A realtime app needs a globally distributed and redundant data stream network.
Globally Distributed Realtime Data Stream Network
The PubNub Data Stream Network takes the rich realtime functionality “building blocks” described above and delivers them on a reliable service running in data centers around the world delivering performance, reliability, and redundancy. Some of the key reasons your app needs a data stream network are:
- Reliable Delivery: Dropped messages break your app. Instantly replicating your messages to data centers around the world ensures that data will always make it from Point A to Point B, even if a data center drops power or the connection to your mobile phone is lost in a tunnel or elevator. PubNub timestamps every message (data slice) to the nearest nanosecond, ensuring deliverability and auditability; providing a reliable message delivery service.
- Handling with the “Real-World Internet”: In the lab, everything works smoothly. But across the broader Internet, things get complicated. How does your realtime system work on 2G/3G/4G? How about cell-tower switching? Transfer from a mobile network to WiFi and back? Firewalls, proxy servers, double-NAT’d environments, even antivirus software can often disrupt your well-designed realtime system. Worse, these are only problems you discover only after a large-scale user deployment. And by then, it’s too late to make changes. PubNub’s Data Stream Network handles all these complexities seamlessly and silently, assuring your realtime app “just works.”
- Multiple Data Centers: What if the data center your realtime servers are hosted in suddenly fails? What happens when your app increases its user base across a wide geographic area and you only have one data center? How do you synchronize realtime data across many servers and data centers? By then it’s too late: you’ve lost users and cast doubt on the reliability of your realtime features. PubNub’s eleven globally distributed network replicates all data globally, and automatically distributes users to their closest data center. Any data center downtimes with trigger a silent traffic redistribution to another data center. In other words, your real-time app will keep working.
It’s all about Deploying and Scaling…
As we said earlier, WebSockets is a protocol, nothing more, nothing less. The PubNub Data Stream Network delivers many realtime services on top of realtime protocols, while also solving the costly and complex deployment challenges for realtime. Being able to effectively deploy and scale out your realtime app ends up being at least 75% of the cost and complexity of a realtime system.
When you plug into the PubNub Data Stream Network, we deliver rich realtime functionality like unicast and broadcast messaging, presence, security, analytics, storage, and lots more. Even more importantly, we handle the network redundancy, routing topology, tunneling, replication and data security. That way, you can focus on the important part: developing your application by focusing on the features that deliver business value.