Author Archive

Multiplayer Gaming

One of the most common implementations of realtime is for multiplayer gaming. It doesn’t require much explaining, you need realtime in order to communicate with your teammates immediately. Many realtime services such as Pusher, Pushpin, and PubNub offer you means to implement instantaneous chat features like cross-platform messaging, private and public chats, typing indicators, and notifications. Other features such as Presence, allow you to get instantaneous notifications of when someone is online or offline as well.

Realtime services such as Ably offer connections state recovery features as well. When a client disconnects abruptly, Ably realtime client will automatically try to reconnect the user every 15 seconds. It will continue this process for up to two minutes to recover the client’s connection.

Here is a visual example of how these features and more could work:

Realtime - Multiplayer Gaming

Resources

Adding Real-Time Multiplayer Support To Your Android Game

Citing Gamesparks, “An excellent example of this is Clash Royale’s deployment system. By allowing players to play a card, and then handing responsibility for movement to the game’s AI, the game mitigates for problems commonly seen on mobile devices, such as a brief drop in connection, keeping the player in the game. So before you start turning to the general challenges of running a real-time multiplayer game, first think about the problems your specific game’s genre might have. This will help you to prioritise your time and efforts into areas where you will see the biggest benefits.”

API Management

API management is the process of creating, publishing, documenting, and overseeing application program interfaces. In other words, API management allows creators to enforce their usage policies, control access, analyze usage, report performance, etc. API management software is often built in-house or purchased as a service. While they may vary, API management software tools typically provide the following functions:

  • Gateway – A server that acts as a API front-end by receiving API requests, enforcing throttling and security policies and passing requests to the back-end server. They can also collect analytic data, provide caching, support authentication, authorization, security, audit and regulatory compliance.
  • Publishing Tools: Collection of tools that define APIs
  • Developer Portal/API store: A community site that encapsulates the services of an API.
  • Reporting/Analytics: Allows developers to monitor API usage.
  • Automation – Controlling connections between an API and the applications that use it.

Realtime

Pushpin - Realtime API

Adding realtime to an API management system can allow API creators to do more if an issue occurs. For instance, if a load becomes too great, realtime integration could allow creators to send instant notifications to a transaction log. It’s possible to combine an API management system with Pushpin, a realtime reverse proxy server. Most API management systems work as proxy servers as well, which means all you need to do is chain the proxies together. Place Pushpin in the front, so that the API management system isn’t subjected to long-lived connections. Also, Pushpin can translate WebSocket protocol to HTTP, allowing the API management system to operate on the translated data.

Resources

Citing APIGEE, “API management solutions should provide the visualization tools, dashboards, and reports to help measure a broad spectrum of data that flows across APIs. This information is most useful in today’s dynamic API economy when it is gathered, analyzed, and provided to the business in real time. Beyond simple charts and graphs, both the ops and business teams should be able to gain deep visibility into the performance of the API program.

In other words, a sophisticated API management solution enables business and operational metrics to provide a complete 360-degree view of your API program.”

Layer

Layer provides developers with APIs, SDKs, and UI toolkits to integrate realtime messaging into your products. They aim to provide developers with the proper tools that matches the rapid development and user experience of leading consumer messengers such as iMessage.

Realtime API - Layer

Layer is 100% managed infrastructure so developers can easily integrate messaging into their applications. In other words, they handle servers, scaling, performance, and encryption as well. They are HIPPA-complaint, designed for asynchronous, person-to-person messaging or business-to consumer uses cases as well. Here are the many services they offer:

  • Direct Messaging and Group Conversations with up to 25 participants
  • Multi-part Messages combining text, rich media content (up to 2GB per part), and application data
  • Granular delivery and read receipts for each Conversation participant
  • Typing Indicators
  • Integrated support for mobile push notifications via APNS and FCM
  • User and Bot Identity profile management
  • A flexible querying interface for searching and retrieving data
  • Blocking and suspension of users
  • Robust connection management and offline support
  • Rich server-side integrations via the Server API and Webhooks
  • An elegant, high-level client programming environment
  • Rapid development of consumer class user experiences via the UI toolkits on mobile and web

Layer’s UI library

Citing Layer, “Layer provides UI libraries to help build apps that work with Layer data. These libraries assume that you are using Layer’s SDKs directly, rather than using your own data-models, or directly using Layer’s Client API (REST API). UI Libraries serve the following goals:

  • Provide a Message List that manages a list of Messages in a Conversation, mark Messages as readwhen they become visible, page Query data as the user scrolls, and managing the scroll position, especially keeping the view pinned to the bottom to continously view new messages as they arrive.
  • Provide Conversation Lists that let you scroll through and select existing Conversations
  • Provide Lists of users that you can create Conversations with

Layer Core Components

Citing Layer, “The Layer UI Libraries ship with a number of widgets to simplify application development. This section explores those widgets in more detail.

Widgets in the Layer UI for Web Library can be broken up into two groups: Main Components which will be discussed here, and documented in depth in the API Reference, and Subcomponents which will only be documented in the API Reference.

  • Conversation Panel: Shows messages and lets the user send their own.
  • Conversations List: Manages a Conversation List and allows the user to select a Conversation
  • Identities List: Manages a list of users that can be selected
  • Notifier: Creates desktop and toast notifications for new messages
  • Presence: Shows current user status
  • Send Button: A button for sending the message that can be added to your Message Composer
  • File Upload Button: A button for selecting and sending a file that can be used to the Message Composer”

Resources

Platform

Documentation

Business Cases

Firebase

Realtime API - Firebase

Firebase is a BaaS (Backend-as-a-Service) that allows developers to create web applications with no server-side programming required. They do this by giving developers the tools to grow their user base. Their initial product was a realtime database, but since they their services and products have grown tremendously:

  1. Firebase Analytics
  2. Firebase Cloud Messaging
  3. Firebase Auth
  4. Realtime Database
  5. Firebase Storage
  6. Firebase Hosting
  7. Firebase Test Lab for Android
  8. Friebase Crash Reporting
  9. Firebase Notifications
  10. Firebase App indexing
  11. Firebase Dynamic Links
  12. Firebase Invites
  13. Firebase Remote Config
  14. Adwords

Realtime Database

Firebase Realtime Database is a cloud-hosted NoSQL in which data is stored in JSON format. The realtime database comes with mobile and web SDKs so you can build apps without the needs of servers. It is optimized for online, when your users go offline, the Realtime Database SDKs use local cache on the device to server and store changes. When they come back online, the local data is automatically synchronized.

Citing Firebase,

  • “Realtime – Instead of typical HTTP requests, the Firebase Realtime database uses data synchronization – every time data changes, any connected device receives that update within milliseconds. Provide collaborative and immersive experiences without thinking and networking code.
  • Offline – Firebase apps remain response even when offline because the Firebase Realtime Database SDK persists your data to disk. Once connectivity is re-established, the client device receives any changes it missed, synchronizing it with the current server state.
  • Accessible from Client Devices – The Firebase Realtime Database can be accessed directly from a mobile device or web browser; there’s no need for an application server. Security and data validation are available through the Firebase Realtime Database Security Rules, expression-bases rules that are executed when data is read or written.”

Resources

Platform

Docs

Ably

Ably is a realtime data delivery platform that provides creators the tools to create, deliver, and manage projects. Their main realtime functionality consists of pub/sub, presence, authentication, encryption, and connection state recovery. They consider these services as a part of their real time core:

Realtime API - Ably Real Time Core

Pub/Sub

Ably organizes the message traffic within applications into named channels.  Clients attach to channels to subscribe to messages, and every message publishes to a unique channel broadcast to Ably subscribers.

Presence

This enables clients to be aware of other clients who are “present” on other channels. Each client has a client identifier and connection identifier. There are other options you can add to see other statuses and attributes as well. This presence is great for building applications that focus on multiplayer games. This allows users to see who is and isn’t in the chat.

Encryption

Ably supports built-in symmetric encryption for message content. When TLS is enabled, messages are securely sent and received from Ably. That means they can never be decrypted by Ably, and can only be decrypted by other clients that share the same key as you.

Connection State Recovery

When a client disconnects abruptly, Ably realtime client will automatically try to reconnect the user every 15 seconds. It will continue this process for up to two minutes to recover the client’s connection.

Reactor Queues

Recently they launched Ably Reactor Queues:

“The queues are traditional message queues that allow realtime data published on pub/sub channels to be consumed in a scalable, resilient and efficient way. Reactor queues provide asynchronous machine-to-machine communication that follows a traditional messaging queuing pattern. At a high level, each machine participates in one or both roles: producers (Ably channels) publish messages (data) to a queue; consumers retrieve messages from the queue. The queue service is responsible for: storing published messages by placing them at the back of the queue; picking off the oldest messages from the front of the queue and handing them to a consumer; ensuring a FIFO or ‘first in, first out’ policy is followed; ensuring messages that are consumed successfully are only handed to one of the consumers. This messaging pattern provides decoupling (publishers can publish without waiting for consumers), scalability (adding more consumers increases throughput capacity) and resilience (messages are stored until a consumer has acknowledged the message has been processed successfully).”

Resources

Platform

Examples

Tutorial

Blog

Documentation

 

Socket.io

Socket.io is a Javascript library that enables bi-directional realtime communication between web clients and servers. It has two main parts: a client-side library that runs in the browser, and a server-side library for Node.js. These components are identical to an API. In layman’s terms, Socket.io allows clients and servers to push messages to each other in real time.

An example of Socket.io + Node.js

Since it’s bi-directional, it uses a WebSocket protocol with long-polling as it’s fallback option. The focus on real-time analytics, binary streaming, instant messaging, and document collaboration. Some of their notable clients are Microsoft OfficeYammer, and Zendesk.

In May 2017, they released Socket.io 2.0. These changes included uws as the default WebSocket engine and developers can create custom parsers.

Use Case

Citing Vaibhav Gautam, “Libraries like socket.IO are needed when we need real time in our app. Let me explain this in little more detail. lets assume that you are developing a game, which is multiplayer and 2 or more users can play that simultaneously. Then in that case you won’t be making HTTP or HTTPS calls because of many reasons and one of them is that their packet size is large and other is that these calls are very slow. In such scenarios we use libraries like sockets to send and receive data to and from server. sockets are really fast and are capable of sending only those data packets which are needed. using HTTP programming you can never create any multiplayer game or any app which will be interacting with server on realtime basis.”

Resources

Demo

Getting Started

Blog

Pusher

Pusher is a hosted service that allows developers to add realtime bi-directional functionality via WebSockets (with HTTP-based fallbacks) to the web and mobile apps. Pusher also offers libraries to integrate into all the main runtimes and frameworks. PHP, Ruby, Python, Java, .NET, Go and Node on the server and JavaScript, Objective-C (iOS) and Java (Android) on the client.

As well as a WebSockets API, they have a HTTP API for publishing your messages. This is ideally suited to web server technologies and they have a set of HTTP API libraries in many common languages to help you to do this.

Pusher - Realtime API

They also have a Publish/Subscribe model that allows developers to filter and control how messages are received.

You can use Pusher to create live activity streams (have feeds update in real times), live data visualizations (choropleth maps that stream new data continuously), live chats, etc!

Pusher API Libraries

Citing Pusher, “Sending and receiving messages using the Pusher API requires libraries. In this section you’ll find libraries for a variety of platforms:

Pusher libraries are divided into 2 categories:

  • CLIENT libraries predominantly consume messages using a WebSocket interface. Think of them as subscribers, although it’s possible to publish messages using Client Events.
  • SERVER libraries publish messages, request information using our HTTP APIauthenticate channel subscriptions, and handle Webhook calls. Think of them as publishers, although it’s possible to subscribe to messages using Client Event Webhooks.”

Resources

JavaScript quick start guide

Client API Overview

Server API Overview

Examples

 

Getting Started with Realtime

How to add realtime capabilities to your products and build realtime APIs

Mirroring the rise of API-driven applications, realtime is becoming an emerging, omnipresent force in modern application development. It is powering instant messaging, live sports feeds, geolocation, big data, and social feeds. But, what is realtime and what does it really mean? What types of software and technology are powering this industry? Let’s dive into it.

What Is Realtime?

Realtime could be defined in a more relative temporal sense. It could mean that a change in A synchronizes with a change in B. Or, it could mean that a change in A immediately triggers a change in B. Or… it could mean that A tells B that something changed, yet B does nothing. Or… does it mean that A tells everyone something changed, but doesn’t care who listens?

Let’s dig a bit deeper. Realtime does not necessarily mean that something is updated instantly (in fact, there’s no singular definition of “instantly”). So, let’s not focus on the effect, but rather the mechanism. Realtime is about pushing data as fast as possible — it is automated, synchronous, and bi-directional communication between endpoints at a speed within a few hundred milliseconds. 

  • Synchronous means that both endpoints have access to data at the same time.
  • Bi-directional means that data can be sent in either direction.
  • Endpoints are senders or receivers of data (phone, tablet, server).
  • Within a few hundred milliseconds is a somewhat arbitrary metric since data cannot be delivered instantly, but it most closely aligns to what humans perceive as realtime (Robert Miller proved this in 1986).

With this definition and its caveats in mind, let’s explore the concept of pushing data.

Data Push

We’ll start by contrasting data push with “request-response.” Request-response is the most fundamental way that computer systems communicate. Computer A sends a request for something from Computer B, and Computer B responds with an answer. In other words, you can open up a browser and type “reddit.com.” The browser sends a request to Reddit’s servers and they respond with the web page.

Request-Response vs Evented APIs

In a data push model, data is pushed to a user’s device rather than pulled (requested) by the user. For example, modern push email allows users to receive email messages without having to check manually. Similarly, we can examine data push in a more continuous sense, whereby data is continuously broadcasted. Anyone who has access to a particular channel or frequency can receive that data and decide what to do with it.

Moreover, there are a few ways that data push/streaming is currently achieved:

HTTP Streaming

HTTP Streaming

HTTP streaming provides a long-lived connection for instant and continuous data push. You get the familiarity of HTTP with the performance of WebSockets. The client sends a request to the server and the server holds the response open for an indefinite length. This connection will stay open until a client closes it or a server side-side event occurs. If there is no new data to push, the application will send a series of keep-alive ticks so the connection doesn’t close.

Websockets

HTTP Web Sockets

WebSockets provide a long-lived connection for exchanging messages between client and server. Messages may flow in either direction for full-duplex communication. This bi-directional connection is established through a WebSocket handshake. Just like in HTTP Streaming and HTTP Long-Polling, the client sends a regular HTTP request to the server first. If the server agrees to the connection, the HTTP connection is replaced with a WebSocket connection.

Webhooks

Webhooks

Webhooks are a simple way of sending data between servers. No long-lived connections are needed. The sender makes an HTTP request to the receiver when there is data to push. A WebHook registers or “hooks” to a callback URL and will notify you anytime an event has occurred. You register this URL in advance and when an event happens, the server sends a HTTP POST request with an Event Object to the callback URL. This event object contains the new data that will be pushed to the callback URL. You might use a WebHook if you want to receive notifications about certain topics. It could also be used to notify you whenever a user changes or updates their profile.

HTTP Long-Polling

HTTP Long Polling

HTTP long-polling provides a long-lived connection for instant data push. It is the easiest mechanism to consume and also the easiest to make reliable. This technique provides a long-lived connection for instant data push. The server holds the request open until new data or a timeout occurs. Most send a timeout after 30 to 120 seconds, it depends on how the API was setup. After the client receives a response (whether that be from new data or a timeout), the client will send another request and this is repeated continuously.

Is pushing data hard? Yes, it is, especially at scale (ex. pushing updates to millions of phones simultaneously). To meet this demand, an entire realtime industry has emerged, which we’ll define as Realtime Infrastructure as Service (Realtime IaaS).

Realtime Libraries

Here is a compilation of resources that are available for developers to build realtime applications based on specific languages / frameworks:

Realtime Infrastructure as a Service

According to Gartner, “Infrastructure as a service (IaaS) is a standardized, highly automated offering, where compute resources, complemented by storage and networking capabilities are owned and hosted by a service provider and offered to customers on-demand. Customers are able to self-provision this infrastructure, using a Web-based graphical user interface that serves as an IT operations management console for the overall environment. API access to the infrastructure may also be offered as an option.”

We often here PaaS (Platform as a Service) and SaaS (Software as a Service), so how are they different than IaaS?

  • Infrastructure as a Service (IaaS): hardware is provided by an external provider and managed for you.
  • Platform as a Service (PaaS): both hardware and your operating system layer are managed for you.
  • Software as a Service (SaaS): an application layer is provided for the platform and infrastructure (which is managed for you).

To power realtime, applications require a carefully architected system of servers, APIs, load balancers, etc. Instead of building these systems in-house, organizations are finding it more cost-effective and resource-efficient to purchase much of this systemic infrastructure and then drive it in-house. These systems, therefore, are not just IaaS, but typically provide both a platform and software layer to help with management. Foundationally speaking, their core benefit is that they provide realtime infrastructure, whether you host it internally or rely on managed instance

It all comes down to the simple truth that realtime is hard for a number of reasons:

  • Customer Uptime Demand – Customers that depend on realtime updates will immediately notice when your network is not performant.
  • Horizontal Scalability – You must be able to handle volatile and massive loads on your system or risk downtime. This is typically achieved through clever horizontal scalability and systems that are able to manage millions of simultaneous connections.
  • Architectural Complexity – Maintaining a performant realtime system is not only complex, but it requires extensive experience and expertise. This is expensive to buy, especially in today’s high demand engineering market.
  • Contingencies – Inevitably, your system will experience some downtime, whether due to an anticipated load spike or a newly released feature. It is important, therefore, to have multiple uptime contingencies in place to make sure that the system knows what to do, should your primary realtime mechanism fail to perform.
  • Queuing – When you’re sending a lot of data, then you likely need an intermediate queuing mechanism to ensure that your backend processes are not overburdened with increased message loads.

Realtime Application IaaS

Realtime app infrastructure sends data to browsers and clients. It typically uses pub/sub messaging, webhooks, and/or websockets — and is separate from an application or service’s main API. These solutions are best for organizations that are looking for realtime messaging without the need to build their own realtime APIs.

Pub-Subscribe PubSub Pattern for Realtime API

These systems also have more well-built platform/software management tools on top of their infrastructure offerings. For instance, the leading providers have built-in configuration tools like access controls, event delegation, debugging tools, and channel configuration.

Benefits of Realtime App IaaS

  • Speed – typically explicitly designed to deliver data with low latencies to end-user devices, including smartphones, tablets, browsers, and laptops.
  • Multiple SDKs for easier integration.
  • Uses globally distributed realtime data delivery platforms.
  • Multiple protocol adapters.
  • Well-tested in production environments.
  • Keeps internal configuration to a minimum.

Use Cases

While some of the platforms out there function differently, here are some of the most typical use cases:

  • Realtime Chat – In a microservice environment, a realtime API proxy makes it easy to listen for instant updates from other microservices without the need for a centralized message broker. Each microservice gets its own proxy instance, and microservices communicate with each other via your organization’s own API contracts rather than a vendor-specific mechanism.
  • IoT Device Control – Securely monitor, control, provision and stream data between Internet-connected devices.
  • Geotracking / Mapping Realtime Updates – Integrates with other realtime APIs like (Google Maps) to construct rich realtime updates.
  • Multiplayer Game Synchronization – Synchronize communications amongst multiple simultaneous players to keep play fluid.

Solutions

Here are some realtime application IaaS providers (managed) to check out for further learning: PubNubPusher, and Ably.

Realtime API IaaS for API Development

Realtime API infrastructure specifically allows developers to build realtime data push into their existing APIs. Typically, you would not need to modify your existing API contracts, as the streaming server would serve as a proxy. The proxy design allows these services to fit nicely within an API stack. This means it can inherit other facilities from your REST API, such as authentication, logging, throttling, etc and, consequently, it can be easily combined with an API management system. In the case of WebSocket messages being proxied out as HTTP requests, the messages may be handled statelessly by the backend. Messages from a single connection can even be load balanced across a set of backend instances.

Realtime API Infrastructure as a service IaaS Proxy

All in all, realtime API IaaS is used for API development, specifically geared for organizations that need to build highly-performant realtime APIs like Slack, Instagram, Google, etc. All of these orgs build and manage their infrastructure internally, so the IaaS offering can be thought of as a way to extend these capabilities to organizations that lack the resources and technical expertise to build a realtime API from scratch.

Benefits of Realtime API IaaS

  • Custom build an internal API.
  • Works with existing API management systems.
  • Does not lock you into a particular tech stack.
  • Provides realtime capabilities throughout entire stack.
  • Usually proxy-based, with pub/sub or polling.
  • Add realtime to any API, no matter what backend language or database.
  • Cloud or self-hosted API infrastructure.
  • It can inherit facilities from your REST API, such as authentication, logging, throttling.

Use Cases

While some of the platforms out there function differently, here are some of the most typical use cases:

  • API development – As we’ve discussed, you can build custom realtime APIs on top of your existing API infrastructure.
  • Microservices – In a microservice environment, a realtime API proxy makes it easy to listen for instant updates from other microservices without the need for a centralized message broker. Each microservice gets its own proxy instance, and microservices communicate with each other via your organization’s own API contracts rather than a vendor-specific mechanism.
  • Message queue – If you have a lot of data to push, you may want to introduce an intermediate message queue. This way, backend processes can publish data once to the message queue, and the queue can relay the data via an adapter to one or more proxy instances. The realtime proxy is able to forward subscription information to such adapters, so that messages can be sent only to the proxy instances that have subscribers for a given channel.
  • API management – It’s possible to combine an API management system with a realtime proxy. Most API management systems work as proxy servers as well, which means all you need to do is chain the proxies together. Place the realtime proxy in the front, so that the API management system isn’t subjected to long-lived connections. Also, the realtime proxy can typically translate WebSocket protocol to HTTP, allowing the API management system to operate on the translated data.
  • Large scale CDN performance – Since realtime proxy instances don’t talk to each other, and message delivery can be tiered, this means the realtime proxy instances can be geographically distributed to create a realtime push CDN. Clients can connect to the nearest regional edge server, and events can radiate out from a data source to the edges.

Solutions

Here are some realtime API IaaS providers (managed/open source) to check out for further learning: Fanout/PushpinStreamdata.io, and LiveResource.

Conclusion

Realtime is becoming an emerging, omnipresent force in modern application development. It is not only a product differentiator, but is often sufficient for product success. It has accelerated the proliferation of widely-used apps like Google Maps, Lyft, and Slack. Whether you’re looking to build your own API from scratch or build on top of an IaaS platform, realtime capabilities are increasingly becoming a requirement of the modern tech ecosystem.