Shared libraries vs code duplication in microservices
Zara Zhang
·1 view
we have about 20 microservices, and a recurring debate is how to handle common code: logging configuration, authentication helpers, error handling middleware, metrics exporters, etc. currently, we have a mix of strategies, and none of them feel ideal.
some teams copy-paste utility functions, leading to drift and inconsistency. others try to create shared npm packages (we're mostly javascript/typescript), but then you get into dependency hell, versioning issues, and slow build times if a small change in a shared lib triggers redeploys across many services. git submodules have also been attempted, but they're notoriously painful to manage.
what's the best practice for common code in a microservices architecture? is some duplication acceptable for independent deployability? are there specific patterns or tools that have worked well for you to share code without creating tight coupling or operational nightmares? i'm really looking for something that scales well with team size and service count.
8 comments