Understanding the TailableEventBus

What is the TailableEventBus?

The TailableEventBus collection in MongoDB is a real-time event propagation mechanism in Elixir Ambience 202x. It leverages MongoDB’s tailable cursors on capped collections to stream transient notifications between system components. For example, it allows the JobEngine to detect new jobs instantly without polling.

How is it configured?

Ambience automatically creates the TailableEventBus in MongoDB as a capped collection with a default size of 10MB. This configuration is embedded in the backend and only applies if the collection doesn’t already exist:

ambience {
  event-bus {
    polling-override: false
    polling-interval: 15 seconds
    initial-review: 1 hour
    expire-after: 1 day  # DocumentDB only
    capped-collection-size: 10M
  }
}

Why might the collection be uncapped?

Several conditions can prevent the collection from being capped:

  • The collection was manually created before Ambience startup.
  • MongoDB sharding is enabled, capped collections are unsupported in sharded setups.
  • The collection was dropped and recreated without restarting Ambience.

How to re-enforce the capped setting?

  1. Stop all Ambience services.
  2. Drop the existing TailableEventBus collection from MongoDB.
  3. Restart Ambience. It will recreate the collection with the default capped settings.

The collection only stores transient event data and can be safely deleted when Ambience is offline.

Symptoms of an uncapped collection:

If the collection isn’t capped, you may notice:

  • Collection size grows beyond 10MB (e.g., 700MB+ or even 20GB).
  • MongoDB performance degrades during bulk runs.
  • JobEngine timeouts due to delayed cursor traversal.