I'm currently working on a project where I'm leveraging Algolia's full-text search capabilities alongside my Firestore users collection. The goal is to have Algolia serve as a near-perfect representation of my users collection minus any personally identifiable information. I've got a working solution, but I'm not sure my implementation is as clean as it could be.
The problem stems from functions of mine that update the user when various actions are taken on my application. Here is a contrived example to illustrate my point:
When a user registers they supply their full name. Their data is then sent to the users collection where a Firestore.onCreate trigger fires, splits that fullName into firstName and lastName, and updates the document. I then have a Firestore.onUpdate trigger that takes out all of the PII and sends that version to Algolia. The problem (I think?) is that I've now sent two operations to Algolia for one user action even though we knew the first action (fullName) would have a second one (firstName & lastName) coming through moments later. (Let's assume this is happening at scale and cost is a concern)
Is there a recommended way to deal with these types of scenarios: an update has side effects that also need to send updates? The first thing that comes to mind is to have logic in the onUpdate trigger that decides whether the change is worth sending to Algolia or not, but that quickly turns a simple operation into a garbage one. I imagine a better approach would be to convert the Firestore.onChange trigger to a basic HTTP Trigger that I fire only when I actually care to change the data, but don't know if that's a bandaid around my lack of understanding. Any guidance on this is greatly appreciated!