Great community here. I am experimenting with event driven architecture with kafka as the event bus and all small services are dockerized and k8s is the hosting platform atm. My question is, how do you get around code duplication for common logic if code sharing is an anti pattern? Insights much appreciated! Will return the favor when I find an opportunity to give back.
That’s a huge topic. My small opinion:
First, don’t worry about it. Duplication is better than dependency!
For really generalized logic, like serialization, date-parsing, etc., you can put that code into a library/package and be sure to use a proper versioning strategy that won’t require all services to be on the same version of the lib.
Another interesting idea is a reusable side-car pattern (since you mention k8s) for common functionality, especially if the services are possibly written in different languages, where the main container can use an API from the sidecar over http or some language-agnostic protocol. This can help put cross-cutting concern like logging, authz/n, etc into a single codebase that other polyglot services can make use of, leveraging this specific k8s capability.
I would also say avoid the function-as-a-service (SOA) pattern - which you may have already concluded if you’ve made the choice for event-driven architecture.
@-dmartines That’s gold! Thanks a mil for the response, I love the side car idea.
@Nhilistic Kabali This is a great book: Building Event-Driven Microservices [Book]. focused more on the “event-driven” part than the general “microservices” aspect, although the topic is covered.