Typescript and Microservice Don’t Mix

I was working as a Software Architect in certain company, which building a microservice system with at least 30 services integrated with each other to build platform.

When i joined to the company and started study the business & technicalities i found them using Typescript & LoopBack framework for building the services.

At first i thought that’s normal and typescript won’t affect microservice development cause i don’t have much experience in typescript and loopback framework but on the other hand i found that the company implement Microservice architecture the wrong way.

As we know CAP Theorem which say in summery that you have 3 ways to build functional system. Build it (Consistent Available), (Partitioned Available) or (Partitioned Consistent).

Consistency (all nodes see the same data at the same time) • Availability (a guarantee that every request receives a response about whether it was successful or failed) • Partition Tolerance (the system continues to operate despite arbitrary message loss or failure of a part of the system).

Availability is the main recipe in the equation of microservice. If you build it (Consistent Partitioned) you gonna lose Availability which will make your microservice maintenance process a living hell and (Consistent Available) means your system is monolithic and not partitioning exist.

So on joining i found them not implementing any of the CAP Theorem models for microservice. No local transactions, no distributed transactions (SAGA), No API gateway, No discovery, No redundancy, nothing just REST API calls and huge mesh of services calling each other and front-end can call them directly without gateway.

A lot of people call that a Microservice, and i call it bullshit.

So i decided to reform the system and make 2 architectural plans

  • Short-Term: in which i will gonna fix the current services with what can be done to postpone problem I anticipate.
  • Long-Term: in which i will implement new architecture for Microservice which adopt (Partitioned Available) model.

As i said before they were using a Typescript for the microservices, so i checked 2 frameworks [Loopback, NestJs] to see if they can support Microservice architecture using (Partitioned Available) model. and i discovered in nutshell that these frameworks are good for (Consistent Available) model only. You can’t build a true microservice project with them.

So i decided to build my framework which will achieve my goal which is (Partitioned Available) model.

After one month of investing in Typescript i discovered a big problem which stopped me, It’s Reflection.

Typescript/JavaScript is dynamic type languages and don’t support advanced reflection like (C++, C#, Java) and i was implementing DDD, CQRS, EventSourcing, Messaging Architecture, SOLID, and to implement such things with true isolation between Domain & Infrastructure, you need a language with high reflection capabilities like languages i just mentioned.

So i discovered that’s why Loopback & NestJs have limitations in the domain of microservice but is that mean typescript is bad, Ofcourse NO.

Typescript is good for Mono-Systems but not for True Micro-Systems due to lack of Advanced Reflection.

Language decision is important when you try to build a Microservice system so always choose right (C++, C#, Java).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: