How to Develop a real-time streaming application with PubNub
Your users want live, real-time data pushed to their apps or feeds instantaneously. With PubNub you can achieve that in a few lines of code, regardless of how many users you have or how much data you are publishing.
Let’s say your application is generating a lot of data and you want to distribute that data to your growing user base. For example:
A multiplayer game, sending game state and character movements to all players.
Weather reports for a rapidly changing storm
The latest stock quotes
Aggregating, analyzing, and distributing sensor data
Social media updates for real-time sentiment analysis.
The latest traffic reports nationwide
Whatever your use case, there is a common requirement to stream and publish data in real-time and have that data received by end users as quickly as possible.
If you want to build that functionality for yourself, you would probably adopt a publish-subscribe architecture, since you publish data to multiple subscribers. You would then need to start thinking about how you would scale that solution… What happens if your user base is geographically diverse? What uptime does your cloud provider offer? How are you going to consume this data on the client across mobile, web, and embedded systems?
Luckily, you don’t have to worry about how you will distribute and manage your real-time data streams because PubNub does that all for you. PubNub can consume any amount of real-time data and distribute it to your entire user base within 100-150ms with 99.999% uptime.
Where can you get started?
These are just examples and the published rate of the demos is artificially capped.
How can I publish data?
Consider the Twitter updates described earlier, the demo makes use of the Twitter Real-time tweet streamer to receive new tweets which are then published to PubNub and PubNub takes care of delivering the data to all interested endpoints, regardless of scale.
If you are new to PubNub or need a refresher on how to publish data, please check out our Tour.
You would substitute Twitter with your own source of data.
PubNub does not impose hard limits on your publish rate but please refer to the publish rate limit recommendations in our documentation. In summary, if you have a very high throughput application (publishing more than 10-15 messages/sec per channel) you should speak with one of our experts who can help with your application architecture.
How can I receive data?
To understand how to receive data, let's look at another stream example, the Wikipedia stream, which is driven by Wikipedia’s event stream.
Any application who wants to receive the data can
subscribe to it. The code below is all you need to receive data from the demo Wikipedia stream.
For your own app you would need to change the
channel name to match how you are publishing your data.
Want to implement your own real-time streaming application?
Sign up for a PubNub account and create your own keys. Try publishing your own data in PubNub to test performance and capability. PubNub offers HIPAA, GDPR, and SOC2 compliance along with a robust security model so we can cater to all data. Remember that demo keys are rate-limited to 5 requests per second so please sign-up and generate a real key prior to testing performance.
Want to discuss things further? Talk to a technical sales representative.