Microservices Contracts: REST vs Native

This is not a new discussion is very old. I remember back into the SOA days - always was something like REST VS SOAP. SOAP is dead and REST own but now is something different.

To be clear - I think REST is the only thing you should use when we talk about External consumers. Like and external API thats would be accessed by a mobile or website.

There are other scenarios like INTERNAL consumers. For this case you can consider using a NATIVE driver instead of REST. So whats is a NATIVE driver? Is just code into a language you are using - so could be Java, Scala, Clojure, Ruby, Go, whatever it does not matter. This idea is similar to the JDBC java driver you have java code to access the database.  So thats the real question when i have internal consumers for my microservices, should they talk to each other tought REST or native driver?

It really depends because both approach have PROS and CONS like everything in life - there are trade offs - but i consider REST in general a more same approach but lately some there are some tech evolution that are changing this game.

REST: The Good Parts

The biggest advantage of REST is interoperability - So you can code one microservice in java and the other one in C for instance and they will be able to talk with other by default. Second great advantage is the unified interface is always same way you dont have that with native clients or soap. Another great quality is abstraction because you dont have any dependency just HTTP and you are free to consume it using any library you want.

Native Drivers: The Good Parts

It`s way more simple to make a java or scala call rather than an HTTP call. Second you can have great advantage in sense of performance and being reactive. You can use RXJava or ReactiveStreams or Akka and gain lots of benefits beyond better performance and non-blocking io. Today you can even not do a remote call instead you can do a IPC call.

Both Have issues

REST for instance is more work for you because you will need to have a mapper to map exceptions to error codes, you will need to have classes to represent the objects you call and also will need make the calls to the service. Besides that you will need to make this for each service - thats the price for flexibility and interoperability. You still could have worst performance because its another layer of remote call and potentially blocking io.

Native drivers have problems as well - they are not a free lunch at all - first and biggest problem is coupling. Because you are calling CODE. Second you could potentially be into a Dependency HELL. Lets say you write down the native driver in scala, all libs you use in your driver will be loaded to your classpath and you might have conflicts like google guava or log4j or xml libraries and you will be tight to that libraries and versions and thats bad because it maybe make hard to you update libraries.

In the end of the day...

REST is best for independence but you can leverage performance from native drivers. You really need think case by case and see what makes more sense for you scenarios and even consider mixed approaches witch is totally fine as well.

Cheers,
Diego Pacheco

Popular posts from this blog

Telemetry and Microservices part2

Installing and Running ntop 2 on Amazon Linux OS

Fun with Apache Kafka