Your Event-Driven system is not Type-Safe

Your Event-Driven system is not Type-Safe

...and how you could make it end-to-end type-safe!

Β·

2 min read

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.

Β