Building Microservices is considered fad these days & with Vert.x 3.0 toolkit, it has never been simpler to build a Microservice in your favorite language
2. AGENDA
• Microservices
• Why, why not ?
• Comparison with Monolithic Architecture
• Vert.x
• Concepts: Event Loop, Verticles, Event Bus
• Modules: core, web
• Comparisons
• Real-life Example - Pulse
3. MONOLITHIC ARCHITECTURE
• Logically Different Modules
• But Packaged & deployed as a Single Unit
• Initial Phases of Project
• Simple to Deploy
• Vertical Scaling
• Later on
• Difficult to Manage & Scale
• Longer Startup Times
• Slow down Development
• CI becomes challenging
4.
5. MICROSERVICES PATTERN
• Split into Smaller, Interconnected Services
• Loose Coupling
• Service == Functional Area
• Service exposes APIs – consumed by other services & clients
8. BENEFITS
• Enforces Modularity
• Decomposing complexity
• Manageable chunks
• Each service – well defined boundary
• Independent Development
• Different Teams
• Different Technologies
• Easy to test
• Scaling is Easy
• Each service can be scaled independently
• Different Service might have different requirements ( CPU, Memory )
11. DRAWBACKS
• Partitioned Database Architecture
• Have to settle for Eventual Consistency
• ACID transactions not possible
• Deploying
• Though scalable, but more complex
• Many more moving parts
• Service Discovery required
12. • Polyglot (Java, JavaScript, Groovy, Ruby, Python etc.)
• Event-driven & Non-blocking programming model
• Super simple Concurrency Model
• Lightweight ~ 650Kb
• “Ideal choice for creating light-weight, high-
performance, microservices”
• Public module repository
• Reactive applications
• Asynchronous APIs
13. CONCEPTS
• Event Loop
• Verticles
• Server Verticles
• Worker Verticles
• Event Bus
• Point to Point
• Pub/Sub
• Distributed
16. • Don’t Block the Event Loop
• Workers “can” block
• Message Passing using Event Bus
• Concurrency Model
• A Verticle instance is always Single threaded
• No more Locking, synchronized & race conditions
• Actor-like concurrency model
• Scaling
• By Creating more Verticle Instances
• For TCP & HTTP servers, Vert.x does automatic load balancing
• Use FAT Jar for Deployment
17. VERT.X MODULES
• Core
• Web
• Data Access
• MongoDB, JDBC, Redis, MySQL
• Authentication Modules
• JWT, OAuth 2, JDBC Auth, Shiro Auth, MongoDB auth
• Messaging Systems
• Kafka, RabbitMQ
• Clustering – Hazelcast
23. ROUTING
• Chain of Routers
• Either “end” it
• Or pass it to the “next” one
• Various Options – Route by
• HTTP Method Type
• Exact Path
• Regex Matching
• MIME type of request
• Decide Routing Order
24. VERT.X WEB
• BodyHandler
• Retrieve Request Body
• Limit Body Size
• Handle File Uploads
• CookieHandler
• Get, Add, Delete Cookie
• SessionHandler
• Sticky & Non-Sticky Sessions
• Vert.x don’t put actual data in Session Cookie – Session UUID is used to
lookup data on the server
• Session timeouts
25. VERT.X WEB
• Authentication & Authorization
• Support for Basic-Auth, Redirect-Auth, FormLogin
• JWT
• OAuth2
• Static Resources
• StaticHandler
• Caching – set headers ( cache-control, last-modified, date )
• Configurable webroot, index page
• Disable File Caching - .vertx
• Templating Support
• Handlebars, Jade, MVEL, Thymeleaf
• CORS & CSFR Handlers
26. DISTRIBUTED SUPPORT
DISTRIBUTED EVENT BUS
• Connect multiple Vert.x
instances across JVMs
• Event bus extends to client side
Javascript
• Ideal for “real-time” web
applications
• vertx-eventbus.js
CLUSTERING
• Hazelcast
• Shared Data Structures
27. REALTIME COMMUNICATION - SOCKJS
• Excellent Support for Low-latency, full-duplex cross-communication
channel
• Tries
• Native Websocket
• Browser specific transport protocols
• Polling for old browsers
• Heartbeats – prevent load balancers & proxies to close long running
http requests
• Vert.x – built in support for SockJS
• SockJS event bus bridge
• Distributed event bus
• Extend’s vert.x server side event bus to JavaScript clients
• vertx-eventbus.js – publish & register messages
28. APPLICATION PACKAGING
• Maven & Gradle Tooling Support
• Packaging
• Use maven-shade-plugin to package as FAT Jar
• Run the Jar
29.
30. MESSAGE TYPES – EVENT BUS
• Primitives & their Boxed Types
• String
• org.vertx.java.core.json.JsonObject
• org.vertx.java.core.json.JsonArray
• org.vertx.java.core.buffer.Buffer
• Custom Type Support – Write your own Serializer
31. REAL-LIFE EXAMPLE - PULSE
• Marketing Cloud Core Service
• REST API for Notifications
• Vertx-Web powered Microservice
32.
33. COMPARISONS
• Vert.x Vs Netty
• Application Vs Infrastructure
• Vert.x provides higher level IO
• Vert.x Vs Jetty
• Vert.x Vs NodeJS
• Use all available cores