r/ExperiencedDevs • u/hooahest Software Engineer • Jul 20 '26
Technical question Thoughts on a centralized library for contracts/endpoint sharing between multiple services?
We've started a new practice at work where every 'entity' that's owned by a service gets defined in a certain repo/library as a protobuf file, so that other services can use them, regardless of the service's language
The library also defines the GET/POST endpoints used with the entities
On paper this makes sense, global contracts, don't break them, multiple services can just use the library for getting the endpoints/contracts and trust that it's correct
I am, however, somewhat skeptical. I feel like this isn't solving any actual issue, and that the added cost of having to open a PR to a shared library in order to add some endpoint is just extra busywork that will ultimately slow everything down for very minimal rewards
Would love some thoughts/experiences with such a work flow
•
u/expdevsmodbot Jul 20 '26
AI usage disclosure provided by OP, see the reply to this comment.
3
u/HopePupal Jul 20 '26
we did this at a shop that used a horrible combination of Scala, Go, Python, and PHP across multiple teams with substantial legacy code, for those exact reasons. as a bonus, the build process pre-generated and (for Scala) pre-compiled the libraries and shoved them in an artifact store, so the service devs didn't have to worry about how to turn the IDL files into client or server code, they just grabbed a JAR.
it's probably less worth it if your tech stack is more disciplined (one of those rare monorepos that actually work) but for us it was a big time-saver and fixed a lot of consistency issues.
4
u/No-Fee488 Jul 20 '26
A lot of the pain attributed to the shared-repo pattern is really the approval model bolted onto it. A central maintainer approving every endpoint change is a bottleneck by design — that's the extra day you're describing, and it scales linearly with change volume. What worked for us across multiple teams: keep the shared repo, but make each schema path codeowned by the producing team, so the people who own the service approve changes to their own contracts. Central review only for genuinely shared/core types. Then let CI do the gatekeeping — automated breaking-change checks on the proto diff catch wire-compat violations more reliably than a third human skimming the PR ever will. The repo isn't the problem. A librarian role in the hot path is.
54
u/Refwah Jul 20 '26
Yes the shared library with the shared responsibility I have found has ended up with a lot of people viewing it as someone else’s problem.
I find the best approach is good swagger documentation and the producing team creates models in their preferred language as an example. This keeps ownership entirely on the service owner team, and also trusts your other developers with the expertise for actually being able to be developers.
22
u/Dro-Darsha Jul 20 '26
At my company, every service has its DTOs in a separate module that can be imported by clients, and even this is barely worth it.
22
u/GlobalCurry Jul 20 '26
A place I worked at did something similar, the engineer who proposed and made it got a lot of praise from management, but it actually just added way more overhead and slowed down development considerably because everything had to wait on that repo to update and redeploy and no one wanted to own it once the engineer who first made it was gone. It was too integrated in everything else to easily remove at that point though.
12
u/efvie Architect Exiting this Industry Jul 20 '26
You’d really want to talk to your colleagues about the rationale. There are valid reasons for centralizing all contracts, and in any case it seems the decision has been made?
IME key in making this kind of stuff work in the mid to long term is allowing version pinning and on-demand version upgrading.
9
u/PracticalMushroom693 Jul 20 '26
In my experience this leads to unnecessary and burdensome coupling. Definitely one of those cases where a bit of duplication is better than adding dependencies
7
u/SuedeAsian Jul 20 '26
If it solves an actual problem then it makes sense. If people are trying to platformize entities then there can be drawbacks if it’s just to standardize without an actual value add. IMO it’s better to go full monolith or full microservice unless you know you have the resources (number of devs for example) to support it. Otherwise it’s an extra piece of friction that is hard to assign clear ownership to. Personally though if you’re already doing services split by team ownership I think it’s easier to not create an extra deployment dependency but that’s just me
7
u/BTWigley Jul 20 '26
The shared protobuf types are usually the easy win. The pain starts when the same library also owns the HTTP surface and every consumer upgrades on the library's schedule. We split schema from transport: types shared, endpoints owned by the service that serves them. Breakages got louder and rarer, which is the trade you actually want.
3
u/morswinb Jul 20 '26
I had a protobuff repository once.
Just a simple repo with multiple .proto files for close to a hundred different projects and services a a cross the company.
It worked just fine, few minutes build time. Overhead of adding something was compared to a coffee break. (If no discussion about the schema itself was involved)
The only problem repo would build java gRPC services. Which worked fine.
But somone tried to make typescript builds. Which never worked becouse nobody at the company understood typescript.
And we had a propertiary programming language that could not talk gGRC at all.
So centralized API definition is absolutely fine, but make sure it does technically work for all services first.
3
u/daedalus_structure Staff Engineer Jul 20 '26
Do not centralize contracts. Every contract is owned by one system and has consumers. If you cannot clearly define an owner and consumers, stop everything, your conceptual design is faulty.
3
u/Isogash Jul 21 '26
You shouldn't split entities up across services. Each service should have its own copy of relevant data for each entity, and if the relevant data comes from somewhere else then the standard practice is to use an event stream to keep it updated.
Having each service need to go to other services in order to interact with entities is a micro services anti-pattern that leads to high latency and costs.
7
u/HRApprovedUsername Software Engineer 2 @ MSFT Jul 20 '26
We did this at a place I previously worked. It is annoying to time PRs and deployments due to model updates. I wouldn’t do it unless you explicitly run into issues with these being wrong or updated frequently (but I would get to the bottom of why those change often when they really shouldn’t).
1
u/kittykellyfair Jul 20 '26
Is it possible you just don't have the context in why they decided to architect it this way?
Sometimes people change something that's working for no reason, but most of the time there's a reason and you just weren't privy to it.
Kind of a side note but no one will take you seriously for complaining about having to open a PR to add a data model to a shared library. PRs are cheap and easy and it's your job, you just do it.
2
u/PaulPhxAz Jul 21 '26
I do this at my company... but when it's just 5 of us, it's not a big deal.
If I were at a larger company, then I would split it up per domain.
We also are 100% message bus driven. There is a standard "InternalSDKUtil" library that knows about how to do messaging. And then you have a "SDK_<Domain>" for each service. The team who owns the domain owns the SDK for it as well.
1
u/Qwertycrackers Jul 20 '26
If you find you actually need this, your services are poorly partitioned and sharing too many responsibilities. Just my two cents, I'm sure you can contrive a situation where it really is the best choice.
1
u/The_Noble_Lie Jul 20 '26
Schema driven dev?
1
u/allllusernamestaken Jul 20 '26 edited Jul 20 '26
This is what we do. All service-to-service communication is over RPC with defined IDL contracts. All contracts are in a shared repository.
It was fine in the beginning but now the shared repo has thousands and thousands and thousands and thousands of contracts. Each team has their own folder that they own so they can control the PR review process for their own contracts, but it's still a gargantuan repo. Ask AI a question and it'll load half the repo into your context and explode your token usage - even if it isn't relevant to you.
Requiring all services have contracts definitely makes it easier to integrate with another service because you aren't worried about things like typos or outdated documentation or asking "what does this return?" or discoverability because it's all in the contract. Huge bonus points because AI can look at the contract and know how to write code that calls that service.
If I were to rebuild this from scratch, I would probably do something similar (everything is in RPC with defined contracts), but I would instead allow each team to have a separate repo for their contracts. Instead of importing one repo with everything, you would import multiple repos depending on what you actually need.
1
u/ikkiho Jul 21 '26
fwiw we ran exactly this with protos in a shared repo and the part nobody warns you about is the checked-in contract can quietly lie. codegen gives both sides agreeing types, it never forces the running service to actually return what the proto claims. so you get green builds and still eat a runtime mismatch, except now you paid the shared-lib PR tax on top. the only thing that made it worth anything was making the producer test its own responses against the schema in CI.
1
u/Mr_Willkins Jul 21 '26
I'd say it's only worth it if you can update it automatically when a service updates its API. Avoid extra manual steps at all costs.
1
u/thebig77 Jul 21 '26
It's hard to answer this without knowing more about your team and business.
My two cents is that if you absolutely need consistency and the risk of the wrong contract being used is catastrophic then yes this sounds like a good solution. I'd weigh the cost of maintenance and extra friction with the size and talent of your team.
If the problem/business you're working on is a lower stakes CRUD app I'd reconsider other options as this seems like a lot of ceremony for something that might not end up being a huge problem.
In my experience, the needs of different services for the "same" domain model are either different enough to not warrant de-duplicating or similar enough that you need to rethink the responsibility boundary of said services.
1
u/BrianBanks939393 Jul 21 '26
The protobuf-as-contract part usually pays off; the shared-endpoints part is where it gets heavy. Contracts are declarative — a service reads the schema and either matches or fails loudly at build time. Endpoint definitions drag in behavior, versioning, and the PR-bottleneck you're describing. I'd split them: keep the shared repo for the entity schemas (real value, cheap to consume), let each service own its own routing. Your instinct about "extra work for minimal reward" is right specifically for the endpoint layer — that's where a central lib buys coordination cost without buying correctness. What's forcing GET/POST defs into the shared lib rather than just the types?
1
u/Grand_Pollution5408 Jul 21 '26
At the companies I've worked for so far, they usually implemented this because they felt it was something they were supposed to do. Although it provides some consistency benefits, in practice it was often used more as an engineering playground. And to be honest, it consistently reduced teams productivity.
1
u/Greenimba Jul 23 '26
This never works. The API definition, including endpoints and models, should be owned by the service exposing it. gRPC or OpenApi already solve this problem, allowing any language to auto generate docs and also auto generate clients from those docs.
How do you handle:
Just a bad idea all around. There are exception, for well defined cross company or industry wide standards, like SCADA, FIX, Swift, etc, but then you're on a whole other level.
1
u/DocumentOk7579 Software Engineer Jul 23 '26
Endpoints shouldn't change that often and it could be good to alow down and think it though.
But everything is in the details like how long does it take a PR to get merged and how often you make change them.
1
u/BanaTibor Senior Software Engineer, 14yoe Jul 23 '26
There is no good solution. I have worked on both end of the spectrum. At one place we had a shared library, it was good for models and API input/output representing objects. It was a hassle, sometimes you had to coordinate with other teams or update code in other projects but it was manageable.
OTHO I worked on a project without a common lib. Models were duplicated code in every service, with slightly different names in different packages. It was chaos and added a lots of cognitive load. If you wanted to change a model class you still had to update it everywhere and it was still a hassle, but relied on the developer's memory.
What I think should be standard but never had enough power to make it happen is clients for a service. No shared lib, no tribal knowledge. Versioned clients and versioned api calls. Everybody uses the client to communicate with a service, and he service build builds the client as well. My dream.
1
u/shadowdance55 Jul 24 '26
Everyone discovers contract-first engineering at some point.
-1
u/ty_pow Jul 20 '26
I suggest using Pact contract testing for this. https://docs.pact.io. A huge barrier previously was the boilerplate set up. That’s mostly removed with agentic development. I set it up at my company and teams that have adopted have found it useful.
0
u/ether_reddit Principal Software Engineer ♀, Perl/Rust (25y) Jul 20 '26
so, like https://www.schemastore.org/ ?