Microservices and Twitter Finagle

Lots of people talk about microservices with REST and thats makes lots of sense because if we think about SOA and Service Orientation Principles we should have interoperability and Rest is great for that.

Such task can be done be a edge service or proxy or api gateway so you really dont need use REST all the time internally.

There is also 2 other important matters like performance for instance, use can use IPC and its way faster than HTTP calls. Second is do something in a JVM language like scala or java - you have benefits doing that. For instance you endup relying more in your compiler and this makes less tests needed and make ir easier to consume services.


Finagle(https://twitter.github.io/finagle/) is used by twitter so if you should dont have doubts about scalability(https://blog.twitter.com/2011/finagle-a-protocol-agnostic-rpc-system). Finagle is built on top of Netty(https://blog.twitter.com/2014/netty-at-twitter-with-finagle). Using it you will give you lots of benefits. Here are some:
  * Connection Pools with throtling
  * Failure Detecture
  * Load Balancers
  * Back Pressure
  * Statistics, Logs and Reports

Finagle is built in Scala and has a very simple and awesome syntax. Finagle uses Futures to perform work. Futures are useful for this kinda of scenarios:
  * Long Cimputations
  * Network calls
  * Reading from disk

All that comes with best of functional programing thanks to scala :-) So you can do all sorts of Higher Order Function and Function First Compositions with map, fold, filter, flatMap, etc... Feature composition is simple and very powerful - I'm a microservice context you deftly need something to deal with composition-calls. You can learn more checking this out(http://monkey.org/~marius/talks/twittersystems/#1).

Finagle has 3 basic ideas: Server, Clients and Proxys. Server can be HTTP rest service with business logic exposed. Clients are libraries that we use the call the Server and proxys are used for all sorts of things - they can act as edge services. Doing all sort of cross cutting concers like: Logging, Security, API Gateway, Redirects, Canary Releases and much more.

Server


The server just have a aplly function and as you can see is very simple and yes there is a Future.

Client


This client code is easy as the Server - Yes Future again - so easy :-)

Proxy


Thats one of the most simple proxys i ever saw.

You can checkout the complete code on my github https://github.com/diegopacheco/Diego-Pacheco-Sandbox/tree/master/scripts/scala/twitter-finagle-playground-fun

Cheers,
Diego Pacheco

Popular posts from this blog

C Unit Testing with Check

Having fun with Zig Language

HMAC in Java