Friday, December 26, 2014

Reactive Microservice Part I

Two of the biggest topics in QCon SF 2014 is reactive service and microservice architecture. Both reactive service and microservice goes hands in hand, you basically can’t build a good microservice systems without being reactive. I’ll start by looking into reactive service architecture and microservice architecture individually and then look into what reactive service architecture means in terms of microservice.

So, what’s reactive systems?

The goal is to build an application that user wants, in-sync data, real-time collaboration, instant feedback and not to wait. Nothing better to describe a reactive systems then the reactive manifesto itself.
Systems built as Reactive Systems are more flexible, loosely-coupled and scalable. This makes them easier to develop and amenable to change. They are significantly more tolerant of failure and when failure does occur they meet it with elegance rather than disaster. Reactive Systems are highly responsive, giving users effective interactive feedback.” –Reactive Manifesto
Defined in the reactive manifesto, to build such a system, we will need to look into 4 traits: responsive, resilient, elastic and message driven.
So back to what a user wants, we’ll have to build a responsive system to user, and the way to get responsive is to be scalable and elastic. For everything to work, build on top of system that’s message driven.
BTW, hopefully by the end of the presentation, you’ll agree with the reactive manifesto and you can head over to the web site and sign it.

And, what’s microservice?

Microservice is to write programs that can be composed together. i.e. write program that do one thing and do it well and for those programs to work together.
the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies” – Martin Fowler


loosely-coupled service oriented architecture with bounded contexts” – Adrian Cockcroft
Some of the interesting descriptions used over QCon are “Old wine in new bottle”, “Hipster of SOA”, “SOA on steroid”.
Microservice architecture can be thought of as a modern version of SOA, without all the bulky technology around SOA, like SOAP and WS-*, each service has a single responsibility (SRP – single responsibility principle.) Even though there’s no formal definition of microservice architecture style, but we can list out some of the common features.
  1. Each service should be simple and have a well-defined interface. It should only have one responsibility so development can be focused and addressed the need of that particular service verse in monolithic application, we often have to scarify part of the application (to use a sub-optimal database or framework) in the name of consistence.
  2. Services are modular and independent. Each can be developed on its own and can be deployed on its own thus providing the fullest expression of encapsulation and modularity.
  3. Relationships between services are more of a graph type than tiers.
  4. Polyglot and individual persistence, each service has its own persistence. It all depends on the use case of a services, it could be a NoSQL database, relational database or a graph database. And the persistence between the services should not be shared, each manage and own its own persistence.
  5. Technology changes rapidly, the best way to keep up with the changes is to build services that are “Strong opinionated, loosely held,” and as each service is small and independent, it would be easy to move on to another technology when required.
So the benefit of adopting microservice are:
  • Each unit is simple
  • Independent scaling and performance
  • Independent testing and deployment
  • Can optimally tune performance (caching, replication, etc)
Of course, it comes with a price:
  • Many cooperating units
  • Many small repos
  • Requires more sophisticated tooling and dependency management
  • Network latencies
We’ll try to address some of the drawbacks later in this document.

Protocol

The most common choice of protocol between services is REST over HTTP and some choose Thrift but Java RPC doesn’t fit here because it’s difficult to maintain backward compatibility. By nature leads to Verb-centric APIs and Use case specific APIs, but we’d want to have APIs that’s more structural as use case specific API are very difficult to navigate the proliferation of APIs, difficult to know which API to use and in many cases, difficult to reuse the API and so we keep creating more and more APIs.

Team Structure

Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization’s communication structure.” – Conway’s law


Conway's law was not intended as a joke or a Zen koan, but as a valid sociological observation. It is a consequence of the fact that two software modules A and B cannot interface correctly with each other unless the designer and implementer of A communicates with the designer and implementer of B. Thus the interface structure of a software system necessarily will show a congruence with the social structure of the organization that produced it.”
So, just by looking at the source code, we should be able to tell the team structure of the teams developed it. Thus our team structure should represent the microservice that we’re building. Google organized their team as “service” and 500px also organized corresponding to the services they are building. Here’s how a typical team should look like.
Small, focused teams
  • Single service or set of related services
  • Minimal, well-defined “interface”
  • Layered on one another
Autonomy
  • Self-sufficient and autonomous (freedom to choose technology, methodology and working environment, responsibility for the result of those choices)
Accountability

  • Give a team a goal, not a solution
  • Let team own the service is the best way to achieve the goal

No comments:

Post a Comment