I need to maintain a consistent state (list of par...
# ask-ai
f
I need to maintain a consistent state (list of participants) for my self-hosted LiveKit cluster. Is it possible to receive a snapshot of the state and then receive incremental deltas via webhooks? Or is it better to constantly poll the ListOfParticipants API?
t
Thanks for reaching out, David. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking whether you can get an initial snapshot via webhooks or whether you should poll
ListParticipants
to keep a consistent participant list for a self‑hosted LiveKit cluster. Short answer and recommended approach first, then a few best practices. Recommended approach (safe and efficient) 1. Get an initial snapshot by calling the
ListParticipants
API on startup or when recovering state. 2. Subscribe to webhooks for incremental events (e.g.,
participant_joined
,
participant_left
,
track_published
,
track_unpublished
) and apply those deltas to your local state. Why this pattern • Webhooks only deliver events that occur after they are configured; they do not provide a historical snapshot. You cannot rely on webhooks to give you the initial full state. • Webhooks are push-based and provide near real-time updates without the load and latency of constant polling. • Polling
ListParticipants
continuously is not recommended because it adds load, increases latency to detect changes, and doesn’t solve race/ordering issues. Key implementation notes / reliability tips • Use
ListParticipants
for the initial full state and then apply webhook events to keep that state current. • Treat webhook delivery as best-effort: ◦ Make your webhook handlers idempotent (use the event
id
for deduplication). ◦ Acknowledge quickly and process heavier work asynchronously. ◦ Persist raw webhook payloads durably so you can reprocess events if needed. • Design for eventual consistency: in distributed/self‑hosted setups you may see short propagation delays, so occasional reconciliation is wise. ◦ Optionally schedule periodic light reconciliation (e.g., occasional
ListParticipants
every X minutes) if you need tighter guarantees — but don’t poll aggressively. • For collisions or recovery: when your service restarts, re-run the initial
ListParticipants
snapshot and then continue applying webhook events. That ensures you don’t miss events that occurred before your process resumed. If you want, I can: • Show a small example flow for initial sync + webhook processing (pseudocode). • Suggest an idempotency/deduplication scheme using the webhook event
id
. • Recommend an appropriate reconciliation cadence based on how strict your consistency requirements are. Which of those would help you most right now? Sources: Best practices for managing webhook event streams | LiveKit | Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name | Handling asynchronous metadata updates in LiveKit | LiveKit
f
@eager-sugar-96686 tag
t
I see you tagged David Grinberg — do you want me to add anything specific for him (a summary, next steps, or implementation details)? If you want me to prepare something to share with David, tell me which of these you'd prefer: • A one-paragraph summary of the recommended approach. • A short checklist of implementation steps (initial sync, webhook handling, idempotency). • Pseudocode example for initial
ListParticipants
+ webhook processing. • A suggested reconciliation schedule (how often to lightly poll for consistency). Which would be most helpful?