DEV Community

Cover image for Your Microservices are probably not Type-Safe ๐Ÿ˜
Marcus Kohlberg for Encore

Posted on

6 5 5 5 5

Your Microservices are probably not Type-Safe ๐Ÿ˜

There's a lot of talk about Type-Safety in programming these days. Yet a lot of programs, especially distributed systems, rely on infrastructure that breaks your type-safety. So what gives? ๐Ÿค”

๐Ÿ’ก Why Type-Safety matters

Type-Safety is mainly about preventing Type Errors, which are errors that usually happen when an operation is performed on a data type it wasn't designed for.

๐Ÿ–ผ Example: Picture this

In your program you're dividing two integers, but instead of an integer, a string of letters is passed to the function. This is a classic example where unintended behaviour can arise and it all might blow up in your user's face. ๐Ÿคฏ

type error

Now you might be saying to yourself: I use a modern programming language like Go or TypeScript, which has type-safety "built-in". That ensures my program is type-safe. Right...?

๐Ÿ˜ Cue the huge elephant in the room

Ensuring your code is type-safe is often only half the battle.

If you're building a distributed system, like an event-driven application using Pub/Sub, it's not enough to ensure that each service is written in a type-safe way.๐Ÿ˜ฌ

๐Ÿ‘ฉโ€๐Ÿฆฏ This is because, normally, Pub/Sub mechanisms are blind to the data structures of the messages they handle, making the inter-service communication un-[type]safe.

This is common source of hard-to-catch errors that can be a nightmare to debug.

๐Ÿฆธโ€โ™‚๏ธ Type-Safe Infrastructure to the rescue

๐Ÿค” What if your Pub/Sub communication could be type-safe? That would prevent a whole class of bugs, and help you catch problems in development rather in production. Saving you time and avoiding plenty of user pains.

๐Ÿ’ก A big part of what we're building at Encore is a fully type-safe Infrastructure SDK that lets you declare infrastructure primitives as type-safe objects in your program.

๐Ÿค This means Encore's compiler can ensure you have end-to-end type-safety, even when using things like Pub/Sub. (Other benefits include that it can also automatically provision the infrastructure in your cloud and deploy your app.)

Try it yourself

๐Ÿ‘‰ Check out this tutorial on building an event-driven system using Encore's Go SDK.

๐Ÿ‘‰ Prefer to use TypeScript? Join the Developer Hangout on Slack to ask for beta access.

Image of Timescale

๐Ÿš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsโ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up