Long story short: I would like to create a plugin system for my microservice architectured app. so we can allow our customers to install their plugins. (something like a plugin system on wordpress|...)
Each plugin:
- Receives
pre/post
hooks for every operation from our microservices (e.g.,productWillBeCreated()
,productHasBeenCreated()
hooks) - It has access to an API to do some operations on our microservices.
My plugin system design: put the plugin(as a server) on another node/container/k8s pod
and then call its methods that are listening to the hooks using RPC calls from our microservices.
Problem: How can we keep consistency while we allow the plugin to call multiple microservices in a hook? e.g., if our plugin calls two microservices to create two entities in one of its hooks, it can fail at the second call.
If it was a monolith
app, we could allow them to put it in a DB transaction(single DB for the whole app), but when we have multiple microservices, we should think of Saga pattern
or a two-phase commit
, which I think none of them is an easy solution when we want to bring to a plugin system. I was thinking about the idempotent implementation for hook handlers or maybe an easy implementation of Saga pattern on plugins.
Do you have a good solution/trick for its consistency problem or another plugin system design that fits microservice architectured apps?
Thanks in advance ❤️