I have a scenario where there are multiple (~1000 - 5000) databases being created dynamically in CouchDB, similar to the "one database per user" strategy. Whenever a user creates a document in any DB, I need to hit an existing API and update that document. This need not be synchronous. A short delay is acceptable. I have thought of two ways to solve this:
Continuously listen to the changes feed of the
_global_changesdatabase.- Get the db name which was updated from the feed.
- Call the
/{db}/_changesAPI with the seq (stored in redis). - Fetch the changed document, call my external API and update the document
Continuously replicate all databases into a single database.
- Listen to the
/_changesfeed of this database. - Fetch the changed document, call my external API and update the document in the original database (I can easily keep a track of which document originally belongs to which database)
- Listen to the
Questions:
- Does any of the above make sense? Will it scale to 5000 databases?
- How do I handle failures? It is critical that the API be hit for all documents.
Thanks!