Eventing function to clear an internal cache within app services

Hi! I am looking at Eventing functionality to solve one of the requirements that I have within my app. I have an app which has several services that only read data from the CB collections. The data in each services stored/cached for 30 mins. Only the API service has write access to the CB database and when any documents get updated via API, I would like to trigger a cache clear within each services. I looked at Eventing, it seems that I can trigger an event using OnUpdate but not sure how to communicate with my cache/app services directly from Eventing function? Has anyone tried or solved this before?

is there a way I could plug in a kafka pub within eventing function so when there’s an update to any docs, i can have my services consume those updates from kafka topic and initiate a cache clear on that particular doc id?

Hi @kshetty1990 - the best option to do this directly from within Eventing would be to use the curl functionality to call out to your external service: https://docs.couchbase.com/server/current/eventing/eventing-curl-spec.html

You may also want to look at the Kafka connector: Introduction | Couchbase Docs. Although this doesn’t integrate directly with eventing, you could consider having a Kafka stream listen to a particular collection and implement the logic within the eventing function to publish into that collection, which would then go into the Kafka topic and on to your application services.

However, I’d also like to understand what your requirements are for caching this data within those separate services and why you don’t have them reading directly from Couchbase? One of the primary reasons for Couchbase’s architecture of a managed caching layer tightly integrated into the database is to avoid the complexity of managing and invalidating separate caching layers.

As a final out-of-the-box option, you might also consider embedding Couchbase Lite into your application services and have it automatically sync data from Couchbase Server (through Sync Gateway) which would give you the best of both worlds: remote caching within the app services, combined with automatic updating of the data as it changes in the database layer.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.