Real-time data
Push updates as they happen. Work smarter with smaller pieces of data flying between systems and users whenever anything changes, powered by Fastly Fanout and design patterns for Real-Time Communications (RTC) at the edge.
HINT: An upcoming edition of Fastly Developers Live on Tuesday, October 31 will focus on real time. Check it out on YouTube and subscribe to be reminded of when it starts!
This visualization shows requests being handled right now by Fastly servers, with the data streaming to your browser using Fanout. Learn how to build this for your own traffic.
Typically, the web is a request-response model, requiring a client to make a request for a resource, which the server fulfils and ends the transaction. For real time communications, this isn't enough, because events can occur anywhere in the system and need to be communicated in any direction, reaching their target immediately (in milliseconds) without being stored, buffered or blocked along the way.
RTC often powers peer-to-peer technologies such as WebRTC. In a Fastly context, real time use cases include proactively pushing messages from the edge to end users, and also notify other parts of your system outside of Fastly of events that happen within the edge application.
Fastly features
Fastly offers a variety of features that make it easy to work with real time use cases:
- WebSockets passthrough allows WebSocket connections to pass messages bidirectionally from end users to your origin servers, through Fastly.
- Fanout offers a pub/sub message bus at the edge, allowing your servers to publish messages in a single API call which can be distributed to millions of end users.
- Streaming miss combined with generous connection time outs and request collapsing allows you to answer an HTTP request by 'dribbling' data slowly on the response, and have Fastly copy that response to multiple users.
- Real time logging delivers log data triggered by events that occur within your Fastly application to any of our supported log providers, or a generic log collector which is compatible with protocols such as syslog or HTTP.
Ideas and typical uses
Fastly customers implement real time data into their applications in a variety of ways. Here are some ideas, based on solutions we've seen customers develop and run on Fastly:
- Live listener/watcher counts: An audio streaming service wanted the ability to keep a count of the active streams tuned into a particular channel, DJ or live stream. With Fanout, you can aggregate these counts and publish batched updates when users start or stop consuming the stream.
- Live comments: When users post comments on a piece of content, push the new comment to all users who are currently viewing the page, making the conversation more engaging and lively.
- Chat: Use WebSockets or streaming miss to maintain connections for 1:1 chat sessions, or Fanout for group chat channels.
- Notifications: Push messaging can be used for notifications of any kind, and while you might commonly use device level notifications such as Apple's or Google's notification APIs, push messaging can be a good alternative for when a user is actively using your application. One customer uses push messaging to send edit notifications to users, to avoid two users making conflicting edits to the same object.
- IOT telemetry: Collecting real time data from a fleet of widely dispersed devices, which may also have limited processing or battery power, can take advantage of Fanout to publish small payloads to an API that's always close by. One customer combines this with push messaging to end users to allow them to view the temperature of their smart grill in real time.
- Price or stock changes: There are many scenarios in which you provide data to users on which they base decisions, and that data can change very quickly. Stock market prices, sports scores, inventory levels, occupancy levels etc, all benefit from being accurate to the second. Users may also feel more inclined to take action if they see prices or inventory changing in front of them.
- Gaming: Fanout is great for turn-based gaming. All the users participating in a game can be subscribed to a game channel using Fanout, and publish moves to the channel. Fanout will relay moves in real time to all the participating players.
- Billing: Using real time or batched logging, capture activity telemetry from your application enabling you to bill customers for their usage of your service, even when requests are satisfied at the edge, reducing the need to have requests go to your origin.
Solutions
The following demos, tutorials, starter kits, and code examples are relevant to this use case. Try them out!
Demos
Sites running on Fastly you can browse. See the principles working for an end user.
Chat Demo for Fanout | Demonstrates the use of Fastly Fanout in a simple web chat app that uses EventStream. |
Fastly Fanout for WebSockets at the edge | Use Fastly Fanout to handle WebSockets at the edge, allowing your application to engage in bidirectional updates with very large audiences in real time. |
Flight departures SSE | Scale low-latency streams of events to huge audiences using server-sent events, ideal for price or page updates, scores, live blogging and more. |
Leaderboard Demo for Fanout | Demonstrates the use of Fastly Fanout to maintain a leaderboard and update it across devices in real time. |
Starter kits
Template Compute applications you can use to bootstrap your project.
Fanout forwarding | Enables Fanout on a service, forwarding to a backend. |
Fanout forwarding starter kit for JavaScript | Enables Fanout on a service, forwarding to a backend. |
Fanout golang starter kit | Implements fanout handlers for Websockets, SSE, etc. |
Push messaging using Fanout | Implements Fanout handlers for WebSockets, SSE, etc. |
WebSockets passthrough | Implements WebSocket passthrough. |
Code examples
Snippets of code ready to copy and paste.
Push prices or breaking news in real time with Server-Sent-Events | Stream responses to the browser while still receiving data from the origin and also saving it to cache. Great for spreading out server-sent-events streams to millions of users from a single source stream. |
Real world usage
Dansons is a leading manufacturer of wood pellet, gas, charcoal, and combination-fueled grills, barbeques, smokers, and portable grills sold under its Pit Boss® Grills, Louisiana Grills® and Country Smokers® brands. When it was time to build a new app for Pit Boss grills, Dansons used the Compute platform and Fanout to create a new entirely serverless model for the communication between grills and the end user client app. Learn more in our Dansons case study.
Both the grill and the client app interact with Fanout running at the edge to publish status updates (for example, the temperature of the grill) and commands.
Switching to app development on Fastly gave Dansons exceptional data transfer speeds 5-7 times faster than their legacy app, cutting the latency between app and grill to less than 5 milliseconds.
Blogs and articles
- Using Kinesis data streams
- Fastly’s real-time log streaming support extends to Apache Kafka and Elasticsearch
- Unlocking real time at the edge
- How to get started with Fastly real-time logging and Compute
- Fastly + Fanout: why real-time messaging and edge computing are an amazing combination
- Server-sent events with Fastly
- Supercharge your API with realtime push powers using Fastly Fanout