Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Java microservice development for high-speed services
Java Microservice lib
QBit
high-speed, in-memory,
services for REST,...
Java microservice development for high-speed services
What is QBit?
❖ Fast queue based service engine!
❖ Services sit behi...
Java microservice development for high-speed services
Why QBit?
❖ Just a lib, does not take over the world!
❖ Works with G...
Java microservice development for high-speed services
Architects / Developers of QBit
❖ Wrote high throughput global servi...
Java microservice development for high-speed services
QBit Speed - FAST!
❖ 200 M in-proc messages a second!
❖ 10M to 100M ...
Java microservice development for high-speed services
It all starts with a fast queue
Java microservice development for high-speed services
Speed First
Java microservice development for high-speed services
Service Discovery / Health
❖ Integration with Consul for
health and ...
Java microservice development for high-speed services
Ease of use and simplicity too
Java microservice development for high-speed services
What is QBit again?
❖ Java microservice development for high-speed s...
Java microservice development for high-speed services
QBit Services
❖ WebSocket RPC, HTTP REST, and in-proc messaging!
❖ I...
Java microservice development for high-speed services
Key Concepts
❖ `!
❖ Queue !
❖ A thread managing a queue. !
❖ support...
Java microservice development for high-speed services
Principles of QBit
❖ Web first (JSON, HTTP, WebSocket)!
❖ Integration...
Java microservice development for high-speed services
QBit Service Example
Domain Object
Service
WebSocket HTTP support
Java microservice development for high-speed services
QBit Example
CURL-ABLE
JSON Output
Java microservice development for high-speed services
Service REST support
❖ Supports Request params, URI params, JSON POS...
Java microservice development for high-speed services
QBit versus….
Java microservice development for high-speed services
QBit versus Spring XXX
❖ Spring what? DI? MVC? Boot?!
❖ QBit Works e...
Java microservice development for high-speed services
Akka vs. QBit
❖ Akka uses actor model!
❖ QBit uses queuing actor-lik...
Java microservice development for high-speed services
Akka and QBit similarities/differences
❖ Akka Typed Actor a lot like...
Java microservice development for high-speed services
Node.js, Vertx
❖ Node.js and Vertx both use a Reactor style design p...
Java microservice development for high-speed services
How does it do?
❖ Faster!
❖ Easier to use!
❖ Focuses just on Micorse...
Java microservice development for high-speed services
Event Bus Overview
Java microservice development for high-speed services
Event Bus
❖ QBit has a high-speed event bus modeled loosely on Vertx...
Java microservice development for high-speed services
Composable Event Bus
❖ EventBus can be composed!
❖ You can use the s...
Java microservice development for high-speed services
Event Bus is an Integration point
❖ Event bus is an integration poin...
Java microservice development for high-speed services
QBit Event Bus
Java microservice development for high-speed services
Private event bus versus System event bus
❖ Private event bus!
❖ htt...
Java microservice development for high-speed services
Simple Example
Java 8 Lambda
Annotation Based
Send
Consumer
Subscrib...
Java microservice development for high-speed services
More involved Example
❖ Advantage of using the event bus with QBit s...
Java microservice development for high-speed services
Channels and Employee
Java microservice development for high-speed services
EmployeeHiringService
Java microservice development for high-speed services
Service that listen
Java microservice development for high-speed services
Java microservice development for high-speed services
Getting a client proxy to a service
Java microservice development for high-speed services
Services are just POJOs
Java microservice development for high-speed services
Wire in POJOs services
Java microservice development for high-speed services
Create a client proxy from service
Java microservice development for high-speed services
Add a new Service Listener?
Java microservice development for high-speed services
New Service
Java microservice development for high-speed services
Event Manager
❖ You can use a private event bus instead of a system
...
Java microservice development for high-speed services
Strongly Type Interface
Java microservice development for high-speed services
Using strongly typed interface to event bus
Java microservice development for high-speed services
Using Strongly typed Event Proxy
Java microservice development for high-speed services
Using Strongly Typed Event Proxy-WIRING
Java microservice development for high-speed services
Working with callbacks
https://github.com/advantageous/qbit/wiki/%5B...
Java microservice development for high-speed services
Callbacks
Java microservice development for high-speed services
Recommendation service callback
Java microservice development for high-speed services
ServiceQueue Proxy for service
Java microservice development for high-speed services
Recommendation service
Java microservice development for high-speed services
Handling a callback
Java microservice development for high-speed services
Java microservice development for high-speed services
Java microservice development for high-speed services
Lambdas are great until you can’t read your code anymore
Lambda call...
Java microservice development for high-speed services
Don’t forget to flush
Auto flushing is available
too!
Java microservice development for high-speed services
But gee what if we have to load the user data?
❖ The first rule is do...
Java microservice development for high-speed services
Java microservice development for high-speed services
Use Callback instead of blocking
Java microservice development for high-speed services
If user is loaded, just call callback
Java microservice development for high-speed services
If you need to load the user, do it async…
Java microservice development for high-speed services
Doing something later…, but not too much later
Java microservice development for high-speed services
Async procrastination a good thing…
Java microservice development for high-speed services
When to handle callbacks?
When your queue is
empty, !
when you hit y...
Java microservice development for high-speed services
Workers for IO, Sharded Services for CPU
❖ QBit allows worker pools ...
Upcoming SlideShare
Loading in …5
×

The Java Microservice Library

8,701 views

Published on

The Java microservice lib. QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. SOA evolved for mobile and cloud. 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.

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.

Find out more at: https://github.com/advantageous/qbit

Published in: Technology

The Java Microservice Library

  1. 1. Java microservice development for high-speed services Java Microservice lib QBit high-speed, in-memory, services for REST, WebSocket and JSON
  2. 2. Java microservice development for high-speed services What is QBit? ❖ Fast queue based service engine! ❖ Services sit behind high-speed queues! ❖ Uses micro-batching and mechanical sympathy to create high speed REST and WebSocket microservice! ❖ Programming model looks like Spring MVC, but enables high-speed async model like Akka, Vertx, Reactor, but easier to program! ❖ Uses Consul or Etcd for clustering, health, cloud config, elasticity ! ❖ Has event bus that can use Kafka, 0Q, etc.! ❖ Uses JSON for wire protocol, works easily with any language over HTTP or WebSocket
  3. 3. Java microservice development for high-speed services Why QBit? ❖ Just a lib, does not take over the world! ❖ Works with Guice or Spring! ❖ Just POJOs written like Java developers write POJOs no steep learning curve! ❖ FAST!! ❖ Easier than reactive, worker pools, sharded services and queued services! ❖ Uses Consul for service discovery, WebSocket for high-speed messaging and REST
  4. 4. Java microservice development for high-speed services Architects / Developers of QBit ❖ Wrote high throughput global services for large high-traffic clients! ❖ F5 crushing load!! ❖ Implemented systems that took other systems 10x to 100x as many servers and 20x #of developers that could handle only 1/10th of the traffic ! ❖ Wrote JSON parser that is 4x faster than mainstream JSON parsers! ❖ Been there, done that for 20+ years. 100+ years building high-speed, reliable systems combined! ❖ Consulting with airlines, plane manufacturers, banks, commodity trading, electronic manufacturing, and other trading systems! ❖ Wrote services that powers some of the busiest sites on the Internet! ❖ Wrote fastest disk batcher for JVM, high-speed, distributed k/v store, in-memory db
  5. 5. Java microservice development for high-speed services QBit Speed - FAST! ❖ 200 M in-proc messages a second! ❖ 10M to 100M in-proc events per second! ❖ 700K to 1,000,000 RPC calls! ❖ Equates to 1.4M to 2M messages TPS! ❖ Using JSON! One Service Thread! One WebSocket!! ❖ Not uncommon to use a fraction of CPU for 2x to 10x to 100x the same performance as a traditional microservice
  6. 6. Java microservice development for high-speed services It all starts with a fast queue
  7. 7. Java microservice development for high-speed services Speed First
  8. 8. Java microservice development for high-speed services Service Discovery / Health ❖ Integration with Consul for health and event bus wiring of peers! ❖ Cloud config! ❖ Peer discovery! ❖ Health Checks! ❖ Serf/Dead man’s switch, gossip, custom
  9. 9. Java microservice development for high-speed services Ease of use and simplicity too
  10. 10. Java microservice development for high-speed services What is QBit again? ❖ Java microservice development for high-speed services! ❖ JSON! ❖ REST! ❖ WebSocket! ❖ Services look like Spring MVC REST / JAX-RS ! ❖ look like Spring Boot, Drop-wizard but work like Spring reactor, Akka, Go, ErLang, etc. ! ❖ Embraces microservices! ❖ Clients can be Web, Mobile, any language that has JSON lib, HTTP lib can use QBit services
  11. 11. Java microservice development for high-speed services QBit Services ❖ WebSocket RPC, HTTP REST, and in-proc messaging! ❖ In-proc, sits behind an actor style queue, gets notified of queue empty, queue limit, queue init, queue start batch, etc.! ❖ Allows reduction of sending IO or calls to CPU intensive services in batches based on queue events! ❖ Batching calls increases system throughput through the system 10x, 100x, 1000x.
  12. 12. Java microservice development for high-speed services Key Concepts ❖ `! ❖ Queue ! ❖ A thread managing a queue. ! ❖ supports batching. ! ❖ queue callbacks for empty, reachedLimit, startedBatch, idle, etc.! ❖ ServiceQueue! ❖ POJO (plain old Java object) behind a queue! ❖ receive method calls and events ! ❖ thread safe! ❖ queue callback methods! ❖ Java idioms looks like Spring MVC REST, JAX-RS! ❖ ServiceBundle ! ❖ Many POJOs behind one response queue and many receive queues. ❖ ServiceServer ! ❖ Exposes services to REST/JSON and WebSocket/JSON communication! ❖ EventBus ! ❖ send a lot of messages to services ! ❖ may be loosely coupled,! ❖ integration with others event buses (Kafka, STOMP, etc.)! ❖ Metrics/Stats: track in-flow, and outflow of messages, other metrics for performance, high-speed time-series database with REST interface! ❖ Meta-Data-Service: Publish track all REST JSON schemas for easy integration and use by third parties
  13. 13. Java microservice development for high-speed services Principles of QBit ❖ Web first (JSON, HTTP, WebSocket)! ❖ Integration via high-speed event bus (Kafka, STOMP, 0MQ, ActiveMQ, etc.)! ❖ Embrace Mechanical Sympathy and Queue Theory to optimize thread hand-off, IO, and core cross talk! ❖ Less is more (be the 95% solution leave the long tail alone)! ❖ Fun and easy to use!
  14. 14. Java microservice development for high-speed services QBit Service Example Domain Object Service WebSocket HTTP support
  15. 15. Java microservice development for high-speed services QBit Example CURL-ABLE JSON Output
  16. 16. Java microservice development for high-speed services Service REST support ❖ Supports Request params, URI params, JSON POST, HTTP GET, etc.! ❖ Customize URIs using annotation! ❖ Reasonable Defaults (annotations not needed)! ❖ Methods available via annotations
  17. 17. Java microservice development for high-speed services QBit versus….
  18. 18. Java microservice development for high-speed services QBit versus Spring XXX ❖ Spring what? DI? MVC? Boot?! ❖ QBit Works easily with DI and Spring Boot! ❖ Competes against Spring MVC but has better thread model for high-speed services, but not all the “features”.! ❖ Spring MVC does a lot. QBit only does Microservices only! So only JSON, REST, and WebSocket! ❖ QBit Enable writing in-memory, high-speed services that can handle 200K TPS to 2M TPS per second single node
  19. 19. Java microservice development for high-speed services Akka vs. QBit ❖ Akka uses actor model! ❖ QBit uses queuing actor-like model + active objects model! ❖ Akka focuses on Queue handlers! ❖ QBit focuses on Services that look / act like Java services in Spring REST, JAX-RS, Java EE, and other frameworks! ❖ QBit is a Java centric model, Akka programming model is similar but foreign to most Java developers! ❖ QBit center of gravity is Microservices = REST, JSON, WebSocket
  20. 20. Java microservice development for high-speed services Akka and QBit similarities/differences ❖ Akka Typed Actor a lot like QBit Service! ❖ QBit Services can be exposed via REST/JSON or WebSocket/JSON! ❖ Both use queue events (empty, init, limit, etc.) to optimize output to IO! ❖ Both are fast! ❖ QBit is library and you can use / compose queues, services as you see fit (you could use QBit in a Spring app)
  21. 21. Java microservice development for high-speed services Node.js, Vertx ❖ Node.js and Vertx both use a Reactor style design pattern based on event bus. (QBit is reactive but using active objects not reactor.)! ❖ At first glance looks a lot like Akka or QBit! ❖ Less granularity on bus, QBit bus speed is a lot faster! ❖ Less control of when queue is idle, empty, etc. QBit has Akka like tuning which is critical to optimize around back pressure.! ❖ Vertx/Node.js are harder to optimize. Harder to compose other handlers. ! ❖ Great for IO and Vertx can be combined with QBit to provide missing pieces for Speed! ❖ Not bad. Not even close to what QBit can do! ❖ QBit works well with Vertx
  22. 22. Java microservice development for high-speed services How does it do? ❖ Faster! ❖ Easier to use! ❖ Focuses just on Micorservices! ❖ Tolerant reader, promiscuous writers! ❖ Uses RAFT and Consul for service discovery
  23. 23. Java microservice development for high-speed services Event Bus Overview
  24. 24. Java microservice development for high-speed services Event Bus ❖ QBit has a high-speed event bus modeled loosely on Vertx style event bus! ❖ Very fast. ! ❖ In-proc but can be integrated with others! ❖ Service methods can be invoked by calls (remote and local behind a queue) ! ❖ Service methods can be invoked by listening to a event bus channels! ❖ You can subscribe to channels or you can consume channels or both
  25. 25. Java microservice development for high-speed services Composable Event Bus ❖ EventBus can be composed! ❖ You can use the system event bus for in-proc service to service messaging! ❖ You can remote replicate events to other servers! ❖ You can tap into an event bus, and/or post events to a service directly for integration with 3rd party systems like Kafka, 0MQ, etc.! ❖ You can use Consul integration to find service peers and compose event bus that allows peers to communicate
  26. 26. Java microservice development for high-speed services Event Bus is an Integration point ❖ Event bus is an integration point! ❖ Can be easily integrated with Camel, ActiveMQ, JMS, Kafka, etc.! ❖ Events come in on same queue as method call! ❖ Event Bus can do remote broadcast and can discover peers via Consul or Etcd
  27. 27. Java microservice development for high-speed services QBit Event Bus
  28. 28. Java microservice development for high-speed services Private event bus versus System event bus ❖ Private event bus! ❖ https://github.com/advantageous/qbit/wiki/%5BRough-Cut%5D-Working- with-private-event-bus-for-inproc-microservices! ❖ Only your module uses it! ❖ System event bus! ❖ https://github.com/advantageous/qbit/wiki/%5BRough-Cut%5D-Working- with-event-bus-for-QBit-the-microservice-engine! ❖ Used by default if you don’t define your own! ❖ Event buses are composable! ❖ events are intrinsic to Services and event buses can be wired to services and other event buses
  29. 29. Java microservice development for high-speed services Simple Example Java 8 Lambda Annotation Based Send Consumer Subscriber
  30. 30. Java microservice development for high-speed services More involved Example ❖ Advantage of using the event bus with QBit services is the events come into same queue that handles method calls so events method calls are thread safe! ❖ Event Bus is very fast. Expect speeds up to 10M to 100M messages a second.! ❖ New example: set of services that handles when a new employees is hired! ❖ Add the employee to payroll system, ! ❖ Enroll employee into benefits system! ❖ Invite employee to our community outreach program! ❖ Four services but the first service will not know about other services
  31. 31. Java microservice development for high-speed services Channels and Employee
  32. 32. Java microservice development for high-speed services EmployeeHiringService
  33. 33. Java microservice development for high-speed services Service that listen
  34. 34. Java microservice development for high-speed services
  35. 35. Java microservice development for high-speed services Getting a client proxy to a service
  36. 36. Java microservice development for high-speed services Services are just POJOs
  37. 37. Java microservice development for high-speed services Wire in POJOs services
  38. 38. Java microservice development for high-speed services Create a client proxy from service
  39. 39. Java microservice development for high-speed services Add a new Service Listener?
  40. 40. Java microservice development for high-speed services New Service
  41. 41. Java microservice development for high-speed services Event Manager ❖ You can use a private event bus instead of a system event bus! ❖ You can use strongly typed proxy to the event bus to abstract channel names and provide a strongly typed bus
  42. 42. Java microservice development for high-speed services Strongly Type Interface
  43. 43. Java microservice development for high-speed services Using strongly typed interface to event bus
  44. 44. Java microservice development for high-speed services Using Strongly typed Event Proxy
  45. 45. Java microservice development for high-speed services Using Strongly Typed Event Proxy-WIRING
  46. 46. Java microservice development for high-speed services Working with callbacks https://github.com/advantageous/qbit/wiki/%5BRough-Cut%5D-QBit-Microservice-Lib- Working-With-CallBacks
  47. 47. Java microservice development for high-speed services Callbacks
  48. 48. Java microservice development for high-speed services Recommendation service callback
  49. 49. Java microservice development for high-speed services ServiceQueue Proxy for service
  50. 50. Java microservice development for high-speed services Recommendation service
  51. 51. Java microservice development for high-speed services Handling a callback
  52. 52. Java microservice development for high-speed services
  53. 53. Java microservice development for high-speed services
  54. 54. Java microservice development for high-speed services Lambdas are great until you can’t read your code anymore Lambda calling Lambda, calling Lambda calling Lambda.! ! Stop using Lambda if your code starts to look like Perl threw up on Lisp.! ! One, to three levels ok.! ! Five or six, can you break this out into a method call or two.
  55. 55. Java microservice development for high-speed services Don’t forget to flush Auto flushing is available too!
  56. 56. Java microservice development for high-speed services But gee what if we have to load the user data? ❖ The first rule is don’t block! ❖ Services can call other services! ❖ When a service might do IO then it should take a callback instead of have a return (generally speaking)
  57. 57. Java microservice development for high-speed services
  58. 58. Java microservice development for high-speed services Use Callback instead of blocking
  59. 59. Java microservice development for high-speed services If user is loaded, just call callback
  60. 60. Java microservice development for high-speed services If you need to load the user, do it async…
  61. 61. Java microservice development for high-speed services Doing something later…, but not too much later
  62. 62. Java microservice development for high-speed services Async procrastination a good thing…
  63. 63. Java microservice development for high-speed services When to handle callbacks? When your queue is empty, ! when you hit your queue limit,! and ! perhaps at the start ! of a new message batch?! ! Handle callbacks before handling new method calls so clients don’t wait around with open connections
  64. 64. Java microservice development for high-speed services Workers for IO, Sharded Services for CPU ❖ QBit allows worker pools for IO bound workers! ❖ QBit allows sharded for CPU bound workers that work on in-memory data! ❖ Or just regular workers! ❖ Queue system can detect when CPU bound services are busy and auto-increase queue batch size

×