i have a multiple node setup on kube for my liveki...
# ask-ai
w
i have a multiple node setup on kube for my livekit RTC, let's say i have node 1 , node 2, node 3 for my RTC. and i have about 40 agents (workers). let's say agent 1 is registered in node 2. if a client SDK ends up joining node 1 through an LB, will agent 1 be forwarded the room request?
t
Thanks for reaching out, Anand. 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 exploring the multi-node Kubernetes setup for LiveKit RTC! In this setup, room requests are smoothly routed even if a client SDK connects to a different node than where an agent is registered, thanks to Redis-based coordination and inter-node message routing. When a client connects to a node that isn't hosting the room, that node kindly acts as a signaling bridge. It uses Redis to find the right hosting node and forwards the signaling traffic there, making sure the client can join the room without any hassle. Likewise, agents are sent to the correct node where the room actually lives, no matter where they initially registered. This is all handled through Redis-backed room location lookups and the agent dispatch system, so everything stays well-coordinated across nodes. If you'd like, I'm here to help with more details or any questions you have about your setup. Just let me know! Sources: Core Platform Architecture & Authentication | livekit/livekit_composite | D... | pkg/service/agent_dispatch_service.go | packages/livekit-server-sdk/src/AgentDispatchClient.ts | Deploy to Kubernetes | LiveKit docs | Distributed Setup | LiveKit docs
w
consistently if a participant joins node 1 and the agent is in node 2, it never gets the request? should I be using AGENT name 100%?
t
I understand how frustrating it can be when agents on different nodes seem to miss requests when a participant joins another node. LiveKit’s architecture is designed to use Redis for cross-node coordination, which helps make sure job requests are routed correctly across the cluster. One important thing to keep in mind is the use of agent names in certain situations to ensure everything flows smoothly. For example: • When you’re explicitly dispatching jobs, it’s essential to specify an
agent_name
that matches the agent’s configuration. • Agent names play a key role in telephony use cases, helping to prevent misrouting or unintended dispatch. It’s also a good idea to double-check that Redis is properly set up for distributed operation, and to keep an eye on agent registration and job assignment logs to see how routing is behaving. If you’d like, I’m here to help you walk through your setup or configuration anytime! Sources: Distributed Setup | LiveKit docs | pkg/service/agentservice.go | Agents telephony integration | LiveKit docs | README.md | Operational Best Practices | livekit/livekit_composite | DeepWiki
w
what is the redis config you'd recommend for a distributed system in kube? im using a compute optimised redis with a 3GB cache size
t
When setting up a distributed LiveKit system on Kubernetes, your Redis configuration plays a key role in making sure everything runs smoothly with high availability, great performance, and easy scalability. Here are some friendly recommendations to guide you: • High Availability: It’s a good idea to use a managed Redis service like AWS ElastiCache, Google Cloud Memorystore, or Azure Cache for Redis. These services come with built-in replication and failover, which helps keep downtime to a minimum and makes managing things a lot easier. • Performance: To keep things speedy, try to deploy Redis in the same region or data center as your Kubernetes cluster. You’re already on the right track with a compute-optimized Redis instance! Just keep an eye on performance metrics to catch any potential bottlenecks early. • Configuration: For your LiveKit setup, make sure all your nodes—RTC, Ingress, and Egress—connect to the same Redis instance. You can specify this using the
redis.address
field in your configuration. • Scaling: If you find yourself needing to scale Redis, Redis Cluster mode is a great option. It helps distribute the load across multiple shards, keeping your system responsive and efficient. If you’d like, I’m here to help with more details on setting up Redis or how to smoothly integrate it with your LiveKit deployment. Just let me know! Sources: Deploying LiveKit | LiveKit docs | Self-hosting the Ingress Service | LiveKit docs | Self-hosting the Egress Service | LiveKit docs | cmd/server/main.go
w
at the moment, my redis seems fine. i've checked all the metrics, the MAX load in the last 7 days have been 60% CPU utilisation so there's no throttling. None of my agents have agent names and i don't create room with the server-sdk. there's a token generated for a room and a direct client side connect to create room, so the RTC is ideally meant to broadcast it to all my agents, it just so happens that some agents are connected to the same node as the client and it works perfectly fine, the other agents dont even get the job request
t
It looks like the issue might be connected to the timing and coordination between agent registration and room creation in your setup. Let’s walk through a few important points to check together: • Agent Registration: Please make sure all agents are fully registered before any room creation happens. In multi-node setups, it’s important that agents are properly registered across nodes so job requests get routed correctly. • Token Configuration: If you’re not using agent names, double-check that your tokens include the right room configuration. For example, the
agents
array in
roomConfig
can help specify how agents are dispatched. • Timing: Creating tokens client-side might not offer enough synchronization. Comparing this with server-SDK patterns, where agent registration is explicitly confirmed before room creation, might be helpful. • Job Assignment Timeout: It’s worth verifying that job requests aren’t timing out. The system has a timeout for job assignment, and any delays in agent registration or room creation could cause jobs to be dropped. Could you please share some details about your agent registration flow and the timing of token creation compared to room creation? Understanding this will really help us identify where the synchronization might be slipping. Sources: Operational Best Practices | livekit/livekit_composite | DeepWiki | CHANGELOG.md | Authentication & Token Management | livekit/livekit_composite | DeepWiki
w
agent is 100% registered properly, i use the server-sdk to generate the token (can i pass roomConfig during token creation?) where do i adjust the job Assignment timeout, I use a room_name regex based acceptance logic in my request_func, if the room_name matches specific pattern the agent either accepts the job or just ignores [pass, i don't do a req.reject()]. Sometimes the job request reaches 5-6 agents and doesn't hit the intended agent
t
Absolutely, you can pass
roomConfig
during token creation using the server SDK. This is a great way to set room-level settings and make sure agents are explicitly dispatched when a participant joins a room. For instance, including agent dispatch rules in the token helps ensure the right agent is assigned to the room. About the job assignment timeout, this is handled internally by the agent worker and isn’t something you can configure through the server SDK or token. Usually, the timeout is set to 7.5 seconds in most SDKs (like Node.js, Python) and 10 seconds in the Go backend. Changing this timeout would mean modifying the agent worker’s source code, which we generally don’t recommend for production environments to keep things stable. To help your job requests reach the right agent, here are a few tips: • Use
roomConfig
in the token to explicitly dispatch the agent to the room. • Make sure agents are registered with the correct
agentName
in their configuration. • Double-check that your room_name regex logic in
request_func
isn’t unintentionally causing jobs to be ignored. If you’d like, I’m here to help you with implementing
roomConfig
or troubleshooting your agent dispatch logic. Just let me know! Sources: agents/src/worker.ts | livekit-agents/livekit/agents/worker.py | Authentication | LiveKit Docs | examples/agent-dispatch/index.ts | web/src/app/api/token/route.ts
w
Copy code
// Package lk provides LiveKit video conferencing integration for interview sessions.
package lk

import (
    "time"

    "github.com/getinteracts/expert-hire-prep/config"
    "github.com/getinteracts/expert-hire-prep/constants"
    "github.com/livekit/protocol/auth"
    "github.com/livekit/protocol/livekit"
)

// GetToken generates a LiveKit access token for a video room session.
// It creates a token with full permissions (publish, subscribe, publish data) for the specified room and user identity.
func GetToken(room, identity string) (string, error) {
    can := true
    at := auth.NewAccessToken(config.GetConfig().Livekit.LIVEKIT_API_KEY, config.GetConfig().Livekit.LIVEKIT_API_SECRET)
    grant := &auth.VideoGrant{
        RoomCreate:     true,
        RoomJoin:       true,
        Room:           room,
        CanPublish:     &can,
        CanSubscribe:   &can,
        CanPublishData: &can,
    }
    at.SetVideoGrant(grant).
        SetIdentity(identity).
        SetValidFor(time.Hour * 2).SetRoomConfig(&livekit.RoomConfiguration{DepartureTimeout: (constants.LIVEKIT_TIMEOUT)})

    return at.ToJWT()
}
where do i specify dispatch logic?
t
To help you specify dispatch logic during token creation, you can include a
RoomConfiguration
object in the access token. This is a great way to define agent dispatch rules and make sure the right agent gets assigned to the room when a participant joins. Here’s a friendly example of how you might do this in your Go implementation:
Copy code
grant := &auth.VideoGrant{
    RoomCreate:     true,
    RoomJoin:       true,
    Room:           room,
    CanPublish:     &can,
    CanSubscribe:   &can,
    CanPublishData: &can,
}

roomConfig := &livekit.RoomConfiguration{
    Agents: []*livekit.RoomAgentDispatch{
        {
            AgentName: "desired-agent-name",
            Metadata:  "{\"key\": \"value\"}",
        },
    },
}

at.SetVideoGrant(grant).
    SetIdentity(identity).
    SetValidFor(time.Hour * 2).
    SetRoomConfig(roomConfig)

return at.ToJWT()
Here are a few key points to keep in mind: • AgentName: This is where you specify the name of the agent to dispatch. Just make sure it matches the agent’s registration name exactly. • Metadata: You can optionally include structured data (like JSON) to give some extra context to the agent. • Multiple Agents: If you want to dispatch more than one agent, simply add multiple
RoomAgentDispatch
entries in the
Agents
array. If you have any questions or need a hand with implementing this or troubleshooting your dispatch logic, please don’t hesitate to reach out. I’m here to help! Sources: Authentication & Token Management | livekit/livekit_composite | DeepWiki | Agent dispatch | LiveKit Docs | examples/agent-dispatch/package.json | livekit-api/livekit/api/agent_dispatch_service.py
w
• AgentName: This is where you specify the name of the agent to dispatch. Just make sure it matches the agent’s registration name exactly. what if this Agent isn't in the same node as the RTC node but is connected to another?
t
Thanks for reaching out! Could you help me understand a bit more about what information you’re looking for regarding agents on different nodes? For example: • Are you curious about how LiveKit keeps communication smooth between nodes? • Do you need some troubleshooting tips for issues with dispatching across nodes? • Or maybe you’re interested in the architectural details of how LiveKit routes jobs across nodes? Knowing this will really help me guide you in the best way possible. Sources: packages/livekit-server-sdk/src/AgentDispatchClient.ts | examples/agent_dispatch.py | Agent dispatch | LiveKit Docs | examples/agent_dispatch/src/main.rs