Wednesday, March 25, 2015

Reactive Programming, Service Discovery, Service types, Client proxy types, Java MicroService Lib update for QBit

Service Discovery

We are integrating now with consul.
This allows services to show health status (up, down, warning).
This is used for service discovery and clustering.
QBit has a clustering event bus (not part of QBit core, but a library).
We had event bus replication. Then we added the clustering by using Consul discovery.
Consul is like ZooKeeper or etcd.

We took what was in the event bus clustering logic and broke that out into a core concept of a ServiceDiscovery.

ServiceDiscovery allows a developer to manage ServicePools.
A ServicePool is a collection of service definitions for a service name, and it fires events when a service is added to the pool, or removed. 

ServiceDefinition is host, port, health, service name and unique service id.

If a service becomes unhealthy using Consul monitoring it gets taken out of the pool.

There is a plan to support a wide variety of ways to do ServiceDiscovery.
Consul is just the first one.

Reactive Programming

We improved the reactive programming support. 
QBit has always been reactive as it is async and uses the Active Object Architecture which is a derivative of the Actor model.

It is now easy to do things like call Service A, call Service B, then use the results from B to call Service C, return the results of A/C, and timeout if A takes longer than 50 ms, timeout if B takes longer than 100 ms, timeout if BC take longer than 250 ms, and timeout if the whole thing takes longer than 250 ms. It does this an async manner. It is wicked fast.

This reactive coordination uses Java 8 lambdas. 

Handling events, REST calls, WebSocket calls are all done through service methods. 
The programming model is POJOs.

QBit is a Java first programming model. It uses common Java idioms to do reactive programming.
It focuses on Java 8. It is one of the few of a crowded field of reactive programming libs/frameworks that focuses on Java 8. It is not a lib written in XYZ that has a few Java examples to mark a check off list. It is written in Java and focuses on Java reactive programming using active objects architecture which is a focus on OOP reactive programming with lambdas and is not a pure functional play. It is a Java 8 play on reactive programming. 

Services can be stateful, which fits the micro service architecture well. Services will typically own or lease the data instead of using a cache.

Service types

Service Bundle, many async services sharing a single result queue and/or sharing a request queue.
Service Server, a wrapper for a Service Bundle that exposes services to the web.
Service Queue, an in-proc, async service.

QBit uses batching queues for performance.

There is also.

CPU Sharded services, each service does a portion of the workload in its own thread to maximize core utilization.
The idea here is you have a large mass of data that you need to do calculations on. You can keep the data in memory (fault it in or just keep in the largest part of the histogram in memory not the long tail). You shard on an argument to the service methods. (This was how I wrote some personalization engine in the recent past).

Worker Pool service, these are for IO where you have to talk to an IO service that is not async (database usually or legacy integration) or even if you just have to do a lot of IO. These services are semi-stateless. They may manage conversational state of many requests but it is transient. 

ServiceQueue wraps a Java object and forces methods calls, responses and events to go through high-speed, batching queues.
ServiceBundle uses a collection of ServiceQueues.
ServiceServer uses a ServiceBundle and exposes it to REST/JSON and WebSocket/JSON.

Events are integrated into the system. You can register for an event using an annotation @EventChannel, or you can implement the event channel interface. Event Bus can be replicated. Event busses can be clustered (optional library). There is not one event bus. You can create as many as you like. Currently the event bus works over WebSocket/JSON. You could receive events from non-Java applications.  


QBit supports creating async clients.

You can use the Client object to create a proxy to a remote service.

You can use the Service Queue object to create a local in-proc proxy to a service.

The programming model is the same for local and remote proxies. 
It is possible to make 720M method calls a second (this include sending the response back) from a single remote proxy.

More to come.

In the mean time.. feel free to read about QBit the Java Microservice Lib that focuses on Microservices, WebSocket, JSON and HTTP using Active Objects and high-speed queueing, messaging and event bus for modern cloud and mobile applications back-ends.

References and reading materials:

1. Microservices by Martin Fowler and James Lewis
2. Microservices Architecture by Chris Richardson
5. Micro service architecure by Fred George
6. Microservices are not a free lunch by Benjamin Wootton
11. Migrating to microservices by Adrian Cockroft
15. Microservices and DevOps by Adrian Cockcroft
16. Building and Deploying Microservices - Bart Blommaerts
17. Microservices on the JVM - Alexander Heusingfeld
18, Microservices Shaun Abrams
19, Java Microservices Architecture -Rick Hightower
21, Reactive Microservices - Rick Hightower

22, High Speed Microservices -Rick Hightower

No comments:

Post a Comment

Kafka and Cassandra support, training for AWS EC2 Cassandra 3.0 Training