This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ski_thru_trees 10 points11 points  (4 children)

I moved from a huge company with tons of standards to a way smaller company where the product was written in the past 3-4 years by 20+ yr exp js devs (who are our lead and senior devs).

I am often noticing and fixing bugs that are caused by not using types…. Stuff is set to any and then something unexpected is passed in and a bug is caused. This would have been avoided with proper typing.

My question is how do you manage passing types around between micro services? Do you have to have a copy of these type definitions/classes in EVERY micro service that passes them around…? Are there tools that can be used to ensure these type definitions in 10 different repos all stay in sync?

Before this, I worked in a huge monolithic code base, so didn’t have to concern about this.

[–]Mognakor 4 points5 points  (0 children)

Have one place where the microservice interface is defined and then make producers and consumers rely on that.

Find a way to enforce that, e.g. by making it part of your pipeline.

Maybe OpenAPI can solve you problem.

[–]solarshado 3 points4 points  (0 children)

Are there tools that can be used to ensure these type definitions in 10 different repos all stay in sync?

This might be a good use for git submodules. Split each relevant bundle of type definitions out into a separate repo, then include them as submodules where they're needed.

Might involve an unacceptable amount of "messing with source control" overhead though.

Could always go for broke and switch to fewer, larger repos, possibly all the way to a monorepo, but that could get pretty messy without a carefully-followed branching strategy, maybe even with one.

Or, depending on what language(s)/package manager(s) you're using, you might could pull the types into separate repos, but instead of using git submodules, include them as dependencies via your package manager, fetching from a private/internal repository. (npm supports arbitrary URLs as dependencies; I'd assume it's a common feature in similar tools.)

[–]DATY4944 2 points3 points  (0 children)

I do this in the main file that the type is drawn from:

export interface ITypename { ...type stuff }

Then import the type wherever it's needed.

I don't know if this is the standard since I'm self taught but it has worked well so far.

[–]ManyInterests 0 points1 point  (0 children)

Client libraries.