For example, I have Service A and Service B where B initiates HTTP requests to A.
How to ensure that the endpoint provided by service A is the same one used by service B.
An counterexample would be service A updates endpoint params, but service B does not catch it.
A remedy would be, both service A and service B import some HTTP endpoint definition from a package, which serves as the single source of truth.
I feel this part of ensuring consistency is best effort based. But I want to know if there is some practical techniques towards that purpose.
A shared lib/package to hold the contract as you suggest is not a guarantee as each service actually needs to import/use the latest version of this external lib/package once it has changed...
There are a few things you can do: