Chapter 1

Key realtime concepts

1. Publish/Subscribe vs. Request/Response

Publish/Subscribe (aka Pub/Sub) is an asynchronous messaging pattern where data is pushed from publishers to subscribers over a distribution mechanism called channels. Publishers publish data to a channel and that data is immediately pushed to all subscribers to that channel. Ideally, different channels should be used for different categories of data.

The core concept behind Pub/Sub and Realtime APIs is pushing new data to all subscribers as soon as it’s published, making it much faster and more efficient than frequently requesting new data. This is in direct contrast to REST APIs, where we must make a request to pull any new data - aka a Request/Response messaging pattern.

A major advantage of Pub/Sub messaging is that publishers and subscribers are completely decoupled so each can continue to operate independently of the other. As such, Pub/Sub messaging increases performance, reliability and scalability in realtime apps.

2. Persistent, stateful connections

In HTTP-based REST requests you establish a connection, request new data, and then wait for a response. Once a response is received the connection is closed. For event-driven applications that rely on low latency data transfer - location tracking, multiplayer gaming, live chat, etc - REST requests simply cannot deliver the required level of performance. This is why Pub/Sub was first developed.

Any realtime communication requires a persisted, stateful connection between a data publisher and subscriber - often with an intermediate routing platform sitting between the two. This is achieved using realtime transport protocols such as WebSockets or MQTT. These protocols allow you to keep the connection open until closed by either party. Any new data is sent and received with low latency as connections don’t need to be frequently re-established.

3. Data Stream Network

Realtime applications require much more than simply building with Pub/Sub architecture. Security, access control, performance, reliability, and scalability are all critical to any realtime application. This is the very problem that a Data Stream Network (DSN) aims to solve. A DSN is a complete realtime Pub/Sub messaging layer that provides these critical functions and more across a globally-distributed cloud network.

Developers building realtime applications using Ably's Data Stream Network don’t need to worry about performance, reliability, scalability, interoperability as all of that is taken care of by Ably. They can instead focus on their core app or business details.

Here’s a simple example of a publisher and subscriber instance when using Ably.

Up next: Fundamental features of Ably →