# Guidance for Optimizing Livestreaming for Betting and Gaming on AWS

## Overview

This Guidance demonstrates betting and gaming setups that deliver video and data streams at low latencies using Amazon Interactive Video Service (Amazon IVS). As an online sports betting or casino content provider, you need to deliver your live streaming workloads to customers worldwide with the lowest possible latency. This Guidance provides multiple latency-optimized configurations for connecting all the required components, from studio to consumer, to enable low-latency delivery.

## How it works

### Less than 300 millisecond latency

This architecture diagram shows how to build a betting and gaming architecture to deliver video and data streams with lower than 300ms latency using Amazon Interactive Video Service (Amazon IVS).

[Download the architecture diagram](https://d1.awsstatic.com/solutions/guidance/architecture-diagrams/optimizing-livestreaming-for-betting-and-gaming-on-aws.pdf#page=1)Step 1Live video is captured from mobile or desktop source devices integrated with the Amazon Interactive Video Service (Amazon IVS) Real-Time Streaming broadcast SDK. It is then encoded and sent as an input to an Amazon IVS stage. An encoder device or an application like OBS Studio can also send video.Step 2Amazon IVS receives the encoded video through Real Time Messaging Protocol (RTMP) over a TLS/SSL connection (RTMPS), WebRTC-HTTP ingestion protocol (WHIP), or WebRTC.Step 3Game metadata is sent to a REST API layer for additional storage and processing and to a player. AWS Direct Connect uses a dedicated connection for a secure and low-latency data (REST or WebSocket) transfer between your on-premises studio and AWS.Step 4Amazon Elastic Kubernetes Service (Amazon EKS) processes REST APIs and WebSockets for game metadata, lobby or chat, and API functionality. It handles players' API calls and maintains WebSocket connections to players for dealer module messages.Step 5Network Load Balancer offers ultralow latencies for latency-sensitive applications to process API communication between players and the application. The timed metadata is sent to the Amazon IVS endpoint.Step 6Amazon CloudFront acts as an endpoint for inbound data flow and customer API requests during the video stream.Step 7AWS WAF protects the endpoints and APIs from distributed denial of service (DDoS) attacks.Step 8Players maintain WebSocket connections to the backend API for lobby or chat and game action calls.Step 9The Amazon IVS player on the client device receives the video stream and metadata. The video and metadata are sent to client applications running the Amazon IVS broadcast SDK through WebRTC. Your viewers can watch live streams globally through the Amazon IVS content delivery network. The Amazon IVS broadcast SDK optimizes performance, reducing the impact on your app and on user devices.### Sub 2 second latency

This architecture diagram shows how to build a betting and gaming architecture to deliver video and data streams with sub 2 second latency using Amazon IVS.

[Download the architecture diagram](https://d1.awsstatic.com/solutions/guidance/architecture-diagrams/optimizing-livestreaming-for-betting-and-gaming-on-aws.pdf#page=2)Step 1Direct Connect uses a dedicated connection for secure and low-latency data (REST or WebSocket) and video (RTMPS or SRT) transfer between your on-premises studio and AWS.Step 2Applications based on Amazon Elastic Compute Cloud (Amazon EC2), like Nginx and Ffmpeg, process video and transcode it into adaptive bitrate streaming-supported HLS, LL-HLS, CMAF, and DASH protocols. Amazon EC2 is chosen over containers to reduce any potential network impact on video latency.Step 3Amazon EKS processes REST APIs and WebSockets for game metadata, lobby or chat, and API functionality. It handles players' API calls and maintains a WebSocket connection to players for dealer module messages.Step 4Network Load Balancer offers ultralow latencies for latency-sensitive applications and distributes the traffic for API metadata services to enable scaling and route traffic to healthy endpoints.Step 5CloudFront distribution delivers your live stream to viewers with low latency and high transfer speeds by using http-based protocols like HLS, LL-HLS, DASH, and CMAF. It also acts as an endpoint for customer API requests during the video stream.Step 6AWS Global Accelerator distributes LL-HLS, DASH, maximum segment size (MSS), WebRTC, or CMAF video traffic to consumers.Step 7The consumer receives the data and video streams through public endpoints and performs synchronization using video timestamps.Step 8AWS WAF protects the endpoints and APIs from DDoS attacks.Step 9Players maintain WebSocket connections to the backend API for lobby or chat and game action calls.### 2-5 second latency

This architecture diagram shows how to build a betting and gaming architecture to deliver video and data streams with 2-5 second latency using Amazon IVS.

[Download the architecture diagram](https://d1.awsstatic.com/solutions/guidance/architecture-diagrams/optimizing-livestreaming-for-betting-and-gaming-on-aws.pdf#page=3)Step 1Live video is captured from mobile or desktop source devices integrated with the Amazon IVS broadcast SDK. It is then encoded and sent as an input to an Amazon IVS video ingest server. An encoder device or an application like OBS Studio can also send video.Step 2Amazon IVS handles video processing (ingesting and transcoding) and synchronizes the metadata with the audio and video frames. As a result, all viewers get the metadata at the same time, relative to the stream.Step 3Amazon IVS HTTP Live Streaming (HLS) playback delivers the live stream and metadata to the Amazon IVS player on a client's device through the HLS protocol.Step 4Direct Connect uses a dedicated connection for a secure and low-latency data (REST or WebSocket) transfer between your on-premises studio and AWS.Step 5Amazon EKS processes REST APIs and WebSockets for game metadata, lobby or chat, and API functionality. It handles players' API calls and maintains WebSocket connections to players for dealer module messages.Step 6Network Load Balancer offers ultralow latencies for latency-sensitive applications to process API communication between players and the application. The timed metadata is sent to the Amazon IVS endpoint.Step 7CloudFront acts as an endpoint for inbound data flow and customer API requests during the video stream.Step 8AWS WAF protects endpoints and APIs from DDoS attacks.Step 9Players maintain WebSocket connections to the backend API for lobby or chat and game action calls.Step 10The Amazon IVS player on the client device receives the video stream and metadata. Your viewers can watch live streams globally through the Amazon IVS content delivery network. The Amazon IVS broadcast SDK optimizes performance, reducing the impact on your app and on user devices.### 3-5 second latency

This architecture diagram shows how to build a betting and gaming architecture to deliver video and data streams with 3-5 second latency using Amazon IVS.

[Download the architecture diagram](https://d1.awsstatic.com/solutions/guidance/architecture-diagrams/optimizing-livestreaming-for-betting-and-gaming-on-aws.pdf#page=4)Step 1Live video is captured from mobile or desktop source devices, encoded, and sent as an input to AWS Elemental MediaLive.Step 2Direct Connect uses a dedicated connection for secure and low-latency data (REST or WebSocket) and video (RTMPS or Secure Reliable Transport (SRT)) transfer between your on-premises studio and AWS.Step 3The video is ingested to MediaLive through the provided endpoint with the following protocols supported: URL_PULL, RTMP_PUSH, RTMP_PULL, and RTP_PUSH.Step 4AWS Elemental MediaPackage ingests the MediaLive adaptive bitrate output and packages the live stream into HLS, Dynamic Adaptive Streaming over HTTP (DASH), and Common Media Application Format (CMAF) protocols. These are then delivered to three MediaPackage custom endpoints.Step 5Amazon EKS processes the REST APIs and WebSockets for game metadata, lobby or chat, and API functionality. It handles players' API calls and maintains WebSocket connections to players for dealer module messages.Step 6Network Load Balancer offers ultralow latencies for latency-sensitive applications and distributes the traffic for API metadata services to enable scaling and route traffic to healthy endpoints.Step 7CloudFront acts as an endpoint for inbound data flow and customer API requests during the video stream. A CloudFront distribution uses the MediaPackage custom endpoints as its origin and delivers your live stream to viewers using http-based protocols such as HLS, low-latency HLS (LL-HLS), DASH, and CMAF.Step 8AWS WAF protects endpoints and APIs from DDoS attacks.Step 9Players maintain WebSocket connections to the backend API for lobby or chat and game action calls.## Well-Architected Pillars

The architecture diagram above is an example of a Solution created with Well-Architected best practices in mind. To be fully Well-Architected, you should follow as many Well-Architected best practices as possible.

### Operational Excellence

Amazon CloudWatch monitors the performance and health of the video streaming infrastructure, enabling proactive identification of performance bottlenecks and other production issues. CloudFront acts as a content delivery network, improving the reliability and speed of content delivery to end users. And Direct Connect provides a dedicated network connection, enhancing the stability and predictability of data transfer between on-premises and AWS environments. Additionally, this Guidance uses MediaLive, MediaPackage, and Amazon IVS for video processing and streaming. Together, these managed services enable efficient monitoring, reliable content delivery, low-latency network connectivity, and a repeatable deployment model. [Read the Operational Excellence whitepaper](/wellarchitected/latest/operational-excellence-pillar/welcome.html)


### Security

This Guidance uses managed services that provide secure endpoints, encryption by default, and least-privilege access policies to protect data and video livestreams. For example, CloudFront provides DDoS protection and SSL/TLS encryption for data in transit. Amazon IVS, which does not store data,encrypts data in transit through HTTPS API endpoints using server-side encryption. Global Accelerator also provides traffic encryption and access controls and integrates with AWS Shield Standard. Additionally, Direct Connect enhances data transfer security by establishing a dedicated, private network connection between your on-premises infrastructure and AWS. AWS WAF then lets you define unexpected access-based criteria to filter. Finally, AWS Identity and Access Management (IAM) policies are scoped down to the minimum permissions required, limiting unauthorized access to resources. [Read the Security whitepaper](/wellarchitected/latest/security-pillar/welcome.html)


### Reliability

This Guidance uses services that provide a robust, scalable, managed, and fault-tolerant architecture. For example, the CloudFront global network maintains content availability, even if one AWS Region experiences issues. The Network Load Balancer improves application availability by distributing traffic across multiple targets and improving fault tolerance. Additionally, MediaLive, MediaPackage, and Amazon IVS work together to provide reliable video processing, packaging, and delivery with built-in redundancy to handle potential failures. Finally, Amazon EKS supports easy scaling of backend services to meet varying demand, enhancing the overall reliability of the system. Together, these services create a highly available and resilient infrastructure capable of handling the high-traffic demands of real-time video streaming and betting operations. [Read the Reliability whitepaper](/wellarchitected/latest/reliability-pillar/welcome.html)


### Performance Efficiency

This Guidance uses services designed to handle the demands of low-latency video streaming and real-time betting applications. For example, Direct Connect ensures stable and fast connectivity between on-premises systems and AWS, crucial for live video ingestion. And as a global content delivery network, CloudFront minimizes latency for delivery to users worldwide. Additionally, MediaLive, MediaPackage, and Amazon IVS provide an optimized video processing and delivery pipeline, reducing encoding and packaging times while maintaining high-quality streams. Global Accelerator further enhances performance by intelligently routing user traffic to the nearest point of presence. Together, these services deliver smooth, low-latency video streams and responsive betting experiences to users, regardless of their geographic locations. [Read the Performance Efficiency whitepaper](/wellarchitected/latest/performance-efficiency-pillar/welcome.html)


### Cost Optimization

This Guidance uses flexible, scalable services that align costs with actual usage. For example, CloudFront and Global Accelerator provide pay-as-you-go pricing for content delivery, and MediaLive and MediaPackage use an on-demand model for video processing and packaging. Likewise, Amazon IVS uses pay-per-minute pricing for live video streaming. Additionally, Amazon EKS enables efficient resource utilization through containerization, potentially lowering compute costs compared to traditional server deployments. Finally, the CloudFront global network removes the need for maintaining multiple content distribution points, reducing infrastructure costs. And because all these services can automatically scale based on demand, you can optimize costs during periods of varying traffic. [Read the Cost Optimization whitepaper](/wellarchitected/latest/cost-optimization-pillar/welcome.html)


### Sustainability

This Guidance uses managed services like CloudFront, MediaLive, MediaPackage, and Amazon IVS, which automatically scale for demand, minimizing unnecessary resource consumption. Additionally, these services provide self-managed data planes that facilitate low-latency delivery of high-quality images without needing separate points of presence, reducing your carbon footprint. [Read the Sustainability whitepaper](/wellarchitected/latest/sustainability-pillar/sustainability-pillar.html)


[Read usage guidelines](/solutions/guidance-disclaimers/)

