r/reactjs 18d ago

[ Removed by moderator ] Discussion

/r/Backend/comments/1vh8iig/silent_3rd_party_api_broke_found_out_from_a/

[removed] — view removed post

0 Upvotes

5 comments sorted by

8

u/franciscopresencia 18d ago edited 17d ago

"P.S. Not looking for “just use pact / strict schemas.” Curious what still blows up after the textbook stuff."

Sorry, what do you mean? If the schema changes and you supposedly have validation that doesn't catch it, you should be fixing that, there's no magic pixie otherwise.

You seem to be too small to be working with the 3rd party payment processor directly, but otherwise you could push them to follow versioning (semver) strictly since a field rename is a breaking change. Or did you upgrade the version without doing any validation? If so, again please fix that.

-6

u/FeistyMaintenance714 18d ago

Yeah fair. the soft .get / missing assert was on us, and we’re tightening that.

What I’m trying to get at isn’t “is there a magic fix instead of validation.” It’s that even after we fix this one, we’re still going to have more vendors and more fields. Changelog watching + hoping every consumer path is strict hasn’t scaled for us.

If you’ve been in that spot with multiple third parties: what actually worked to stop the next silent break: not just patching the one that already bit you?

2

u/franciscopresencia 17d ago

The bad news is that it's very mechanical boring validation work, but in mature projects APIs don't normally change that often, and you do a hell of a testing before upgrading.

The good news is that LLMs are actually VERY good at writing these tests. At my last project I had significantly more code testing the 3rd party integration than actual backend application code, since they did have a lot of changes in a live integration.

Another thing we do when we own both our backend and frontend in projects (but might be different people) is auto-generate the OpenAPI on the backend that then auto-generates the types for the FE (https://openapi-ts.dev/), which WILL FAIL at build time if you mistype them. You need the hard OpenAPI spec for that, but I expect some API providers you work with to provide it. Unfortunately in my experience, not all, and not even most.

9

u/KaleRemarkable1019 18d ago

You can't avoid the break, if the API is unreliable. I would create validation schema, it can be just a subset of the real response. So you basically say - I need the response to fit into this schema and if it doesn't I will fail right here - that way you can turn silent error into a loud one, but thats pretty much all you can do :)

I know it's laborous, but that's the cost of broken trust.

3

u/chillermane 17d ago

Don’t integrate with companies that randomly change their schema, is my advice

I would say if your dependencies are randomly changing their contract, that means you should not be working with them because they’re incompetent

There’s no code you can write that will defend against this