it seems that sometimes concurrent calls to create...
# ask-ai
s
it seems that sometimes concurrent calls to createroom with a specific roomname ends up in room duplication with 2 active rooms with the same roomname. is there a way to prevent this?
t
Thanks for reaching out, Ale. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're right to be concerned — concurrent
CreateRoom
calls can produce multiple active rooms with the same room name due to race conditions. Here are practical ways to prevent that, and which to choose depending on your needs. What’s happening • LiveKit does not enforce global uniqueness of room names, so simultaneous
CreateRoom
requests can each succeed and create separate rooms (only the Room SID is guaranteed unique). Recommended options • Let rooms be auto-created on participant join (best): don't call
CreateRoom
manually. LiveKit will create the room when the first participant connects with a valid token, which removes the race entirely. • Use external synchronization (when you must call
CreateRoom
): acquire a distributed lock per room name (Redis, database row lock, etc.) so only one request creates the room. • Make room names unique: append a timestamp, UUID, or counter to the name to avoid collisions if coordination is difficult. If you want, I can: • Show a short pattern for using a Redis lock around
CreateRoom
. • Outline how to switch to auto-creation and issue tokens for first-join behavior. Which would you prefer? Sources: Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name | CreateRoom() is Taking Too Long