As I understand from the docs, each worker registe...
# ask-ai
f
As I understand from the docs, each worker registers itself with a LiveKit server to receive jobs. Is there an example or a recommended setup for distributing workers evenly across multiple LiveKit server nodes? Or can workers instead form a common pool shared between all LiveKit servers?
t
Thanks for reaching out, Vlad. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're interested in how LiveKit manages worker distribution! LiveKit has a handy built-in system that evenly spreads workers across multiple server nodes using a round-robin method. This means each job is assigned to just one worker at a time, and if a worker doesn’t pick up a job within a certain timeout, the system thoughtfully reassigns it to another available worker to keep things running smoothly. If you want to create a shared worker pool across several LiveKit server nodes, setting up a distributed environment with Redis is the way to go. Redis serves as both the room data storage and message bus, allowing all nodes to share information about the cluster. This helps them make smart decisions about routing jobs based on who’s available and how busy they are. With this setup, any worker can connect to any LiveKit server node and join the shared pool seamlessly. Once you have Redis configured, you don’t need to worry about additional setups—the built-in load balancing system will take care of distributing jobs evenly across all workers in the pool automatically. It’s designed to make your life easier! Sources: Distributed Setup | LiveKit Docs | Worker lifecycle | LiveKit Docs | Agent dispatch | LiveKit Docs | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | Deploying to custom environments | LiveKit Docs
f
thanks! are you able to share me a link to a source code where I can check reconnection of worker from one livekit server to another?
t
I'd love to help you out! Could you please share which programming language or SDK you're using for your workers? That way, I can provide you with the best and most relevant source code example for the reconnection logic. Sources: src/room/events.ts | delay-handling/raw_data.txt | agents/src/worker.ts | livekit-agents/livekit/agents/worker.py | How We Built a Globally Distributed WebRTC Mesh Network
f
t
Thank you so much for sharing the link! The repository you’ve provided includes the LiveKit agents, which have some great examples and implementations for worker setups. You can take a closer look at the reconnection logic and other worker-related features right there in the codebase. If you’d like, I’m here to help you navigate through the repository or answer any specific questions you might have about the implementation. Just let me know!
f
are you able to share me a link to a source code where I can check reconnection of worker from one livekit server to another?
t
I understand you're looking for an example of worker reconnection between different LiveKit servers. While the LiveKit agents repository doesn't have a direct example for this, the current worker implementations do show how to handle reconnection with retry mechanisms for the same server. The great news is, you can build on this by cycling through multiple server URLs during reconnection attempts to support multi-server failover. If you'd like, I'd be happy to walk you through how to adjust the existing reconnection logic to include this feature. Just let me know, and I'll assist you every step of the way! Sources: examples/voice_agents/llamaindex-rag/data/raw_data.txt | README.md | livekit-android-sdk/src/main/java/io/livekit/android/room/RTCEngine.kt | How We Built a Globally Distributed WebRTC Mesh Network
f
you said "Redis serves as both the room data storage and message bus, allowing all nodes to share information about the cluster. This helps them make smart decisions about routing jobs based on who’s available and how busy they are. With this setup, any worker can connect to any LiveKit server node and join the shared pool seamlessly." can you share me a code example of this implementation?
t
I'm glad you're looking to configure Redis for room data storage and as a message bus in LiveKit! Here's a helpful YAML configuration example that you can use to get started:
Copy code
# Basic Redis configuration
redis:
  address: redis.host:6379
  # db: 0
  # username: myuser
  # password: mypassword

# Sentinel configuration (high availability)
redis:
  sentinel_master_name: livekit
  sentinel_addresses:
    - livekit-redis-node-0.livekit-redis-headless:26379
    - livekit-redis-node-1.livekit-redis-headless:26379
  # sentinel_username: user
  # sentinel_password: pass

# Cluster configuration
redis:
  cluster_addresses:
    - livekit-redis-node-0.livekit-redis-headless:6379
    - livekit-redis-node-1.livekit-redis-headless:6380
  password: cluster_password

# TLS configuration
redis:
  address: redis.host:6379
  tls:
    enabled: true
    insecure: false
    server_name: myserver.com
    ca_cert_file: /path/to/ca.crt
    client_cert_file: /path/to/client.crt
    client_key_file: /path/to/client.key
Once you have Redis set up, LiveKit will seamlessly switch to distributed mode. This enables room state synchronization, PubSub messaging, distributed locking, and multi-node routing—all working together to create a smooth experience. If you run into any questions or would like some guidance with implementation or exploring the codebase, please don’t hesitate to reach out. I’m here to help! Sources: Distributed Setup | LiveKit Docs | config-sample.yaml | redis/redis.go | internal/bus/bustest/redis.go