Skip to content

Livekit Overview

LiveKit is an open-source infrastructure for real-time audio and video applications, designed to provide developers with an easy-to-integrate and highly scalable solution. Unlike traditional WebRTC-based applications that require extensive backend management, LiveKit offers a complete Real-Time Communications (RTC) stack that simplifies the development process while ensuring performance, security, and flexibility.

LiveKit operates as a server-based WebRTC infrastructure that manages real-time communication through a centralized SFU (Selective Forwarding Unit). Unlike traditional WebRTC P2P architectures where all participants send media streams to each other, LiveKit optimizes media routing by relaying streams through a central server, reducing bandwidth consumption and improving performance.

LiveKit's architecture is designed to scale horizontally, meaning that it can handle thousands of participants through load balancing and cloud-based deployments (Kubernetes).


Livekit main concepts

LiveKit consists of several key concepts that work in tandem to deliver a powerful and scalable video conferencing solution. Below is a breakdown of the LiveKit components, their roles, and how they contribute to the overall functionality of the platform:

1) LiveKit Server

The LiveKit Server is the core component that handles signaling, media routing, and participant management, with key features such as:

  • Media Routing (SFU):Uses a Selective Forwarding Unit (SFU) architecture to efficiently route media streams between participants, optimizing bandwidth and reducing direct peer-to-peer connections.
  • TURN and STUN Support: Facilitates NAT traversal, with STUN and TURN.
    • STUN (Session Traversal Utilities for NAT) is a protocol and server that helps devices discover their public IP address and port when behind a NAT (e.g., a home router).
    • TURN (Traversal Using Relays around NAT) is a protocol and server that acts as a media relay when direct peer-to-peer connections are impossible (e.g., due to strict firewalls or symmetric NATs).
  • Deployment Flexibility: The server can be deployed in various environments, including cloud platforms, on-premises servers, and Kubernetes clusters, allowing for scalable and adaptable setups.

2) LiveKit SDKs

LiveKit provides comprehensive SDKs for multiple platforms, making it easy to integrate real-time communications into web, mobile, and game applications. The SDKs support:

  • Cross-Platform Integration: SDKs are available for Web, iOS, Android, and Unity, enabling seamless integration of audio/video communication.
  • Real-Time Media Handling: The SDKs offer APIs for managing media streams, room participants, and events related to room activities (e.g., participants joining/leaving).
  • Adaptive Bitrate Streaming: Ensures high-quality media experiences even under varying network conditions by adjusting the video/audio quality based on the available bandwidth.

3) LiveKit Cloud

LiveKit Cloud is a fully managed service that simplifies deployment and maintenance by hosting LiveKit in the cloud. Key benefits include:

  • Automatic Scaling: Cloud-hosted LiveKit dynamically scales based on usage, ensuring optimal performance during high traffic without requiring manual configuration.
  • Security: Built-in security features like end-to-end encryption ensure that communications remain private and protected.
  • No Setup Required: Developers can focus on building their applications while LiveKit Cloud manages the infrastructure, eliminating the need for manual server setup and management.

4) LiveKit Rooms

A Room is a virtual space in which participants can join, interact, and exchange media streams. LiveKit Rooms offer:

  • Dynamic Room Creation: Rooms can be created and managed programmatically via LiveKit's API, offering flexibility in how meetings or events are structured.
  • Multi-Participant Support: Rooms can accommodate multiple participants, enabling collaborative features like screen sharing and real-time messaging.
  • Screen Sharing and Data Channels: Participants can share their screen, and rooms support data channels for text or file sharing, enhancing collaboration within the room.

5) LiveKit Tracks & Streams

Each Track represents an individual media stream (audio, video, or data) published by a participant. Key features include:

  • Track Publishing and Subscription: Participants can publish their own media tracks and subscribe to others' tracks to receive and display media content.
  • Stream Prioritization: Tracks can be prioritized to ensure that critical media (e.g., active speaker or shared screen) gets higher bandwidth allocation, optimizing the user experience.

6) LiveKit Webhooks & Events

LiveKit supports webhooks to notify external services about room events and participant activities. This feature is vital for:

  • Real-Time Notifications: Webhooks notify external systems when events occur (e.g., participant joins, media streams start or stop), enabling integrations with recording services, analytics platforms, and other third-party tools.
  • Custom Workflow Integration: Developers can configure webhooks to trigger specific actions based on room events, facilitating the automation of various processes like recording, notifications, or integrations with CRM systems.

7) LiveKit Recording & Storage (Egress)

The Egress component extends LiveKit by enabling audio and video recording. Once a session is recorded, it can be stored or uploaded to external platforms like YouTube, AWS S3, or Google Drive. Key points include:

  • Automated Recording: Through LiveKit's webhook system, recordings are automatically started when a session begins and stored/uploaded once completed.
  • Flexible Storage Solutions: Recordings can be saved to a variety of cloud storage platforms, giving flexibility based on business needs.

Livekit key architecture concepts

The four main LiveKit components in our setup are:

flowchart LR
    A[Caddy] --> B[LiveKit Server]
    B --> C[Redis]
    B --> D[LiveKit Egress]

1) LiveKit Server (livekit/livekit-server)

This is the core component that handles media routing, session management, and signaling. It enables clients to connect and exchange media in real-time. The LiveKit server processes:

  • Session Management: The LiveKit server is responsible for creating, managing, and terminating user sessions. Each session represents a video conference room, where participants can join, leave, or interact in real-time. It maintains participant states, room configurations, and handles session cleanup when participants leave or when the session ends.
  • Media Routing: In a LiveKit-powered environment, media streams are routed from one participant to others through the server. This ensures that all video/audio content is transmitted efficiently across all participants. LiveKit dynamically adjusts the media streams based on network conditions and the number of participants to optimize bandwidth usage. The server decides which streams should be sent directly (peer-to-peer) or relayed through the server (server-to-client).
  • Authentication: The LiveKit server handles access control and authentication through JWT (JSON Web Tokens). Before a user can join a session, a valid token must be generated, ensuring that only authorized users can access protected rooms. Tokens are generated by the backend server and contain metadata about the user, session, and any required roles or permissions.
  • Signaling: The LiveKit server facilitates the exchange of WebRTC signaling data (like ICE, which is a protocol responsible for facilitating the connection between devices over the Internet, and SDP which is responsible for negotiating the parameters of a multimedia session between the devices) between clients to establish direct peer-to-peer connections. This ensures that each participant can join the room and start communicating seamlessly.

2) Caddy (livekit/caddyl4)

Caddy serves as the reverse proxy and SSL termination layer, ensuring secure and efficient communication between clients and the LiveKit server. It is responsible for:

  • SSL/TLS Termination: Caddy automatically manages SSL certificates using Let's Encrypt. It ensures that all connections to the server are encrypted using HTTPS, providing a secure environment for communication. This also means that sensitive data, including media streams and tokens, are protected during transmission.
  • Load Balancing: In a large-scale deployment, traffic from users may need to be distributed across multiple LiveKit servers. Caddy helps with load balancing, ensuring that traffic is routed efficiently to the available servers and reducing the chances of overloading any single instance.
  • Request Proxying: Caddy handles incoming API requests (such as authentication and media signaling) and forwards them to the appropriate backend services. It also proxies WebRTC media traffic to ensure that the media streams flow correctly between clients and the LiveKit server.
  • Cross-Origin Resource Sharing (CORS): Caddy also manages CORS headers, allowing clients from different domains to securely interact with the LiveKit server by enabling cross-origin requests.

3) Redis (redis:7-alpine)

Redis is an in-memory data structure store used to support real-time operations and improve the performance of the LiveKit server. It is key to:

  • Session Storage: Redis is used for storing session-related data that needs to be accessed quickly. It stores information like room configurations, active participants, and ongoing media sessions. Redis enables the LiveKit server to quickly retrieve and update session data without needing to query a disk-based database, reducing latency.
  • Real-time Signaling: Redis is used to support real-time event handling, such as participant joins and leaves, media stream state changes, and signaling messages. It acts as a pub/sub (publish/subscribe) system, allowing the LiveKit server to broadcast updates to all connected clients in real-time, without delays.
  • State Management: Redis helps manage the internal state of the server, such as the number of active sessions, stream states, and user preferences. It ensures that the server can quickly and efficiently scale across multiple instances by providing a shared memory space accessible by all containers.
  • Scalability and Persistence: Redis supports horizontal scaling, allowing you to run multiple instances of the LiveKit server while ensuring consistent state across all instances. In the event of a server restart, Redis helps persist session and signaling data, enabling fast recovery.

4) LiveKit Egress (livekit/egress)

The LiveKit Egress component is responsible for handling media recording and streaming. It enables:

  • Recording: LiveKit Egress allows you to record video and audio from a live session. The recordings can be saved in various formats, such as MP4, WebM, or HLS, depending on your needs. This feature is crucial for capturing meetings, webinars, or interviews that can later be shared or analyzed. Egress can record all streams in a session, or it can focus on specific participants or shared content (like screens or presentations).
  • Live Streaming: LiveKit Egress can also stream sessions to external platforms like YouTube, Twitch, or any custom RTMP endpoint. This is useful for broadcasting a session to a wider audience beyond the conference participants, such as webinars or large events.
  • Output Customization: The Egress component provides options for customizing the output of recorded streams, including video quality settings, audio tracks, and whether to include or exclude participant interactions (such as muting certain participants during the recording).
  • Compatibility: Egress works with all other LiveKit components to ensure smooth recording and streaming. It can seamlessly integrate with the LiveKit server, leveraging the session management and media routing capabilities to ensure that the right media is captured and streamed without interference.

For further and more detailed information, please consulte the official Livekit documentation.