During past years, the requirements for modern applications have increased from gigabytes of data to terabytes, from thousands of requests per second to millions, from seconds of response time to milliseconds, and this list can be continued. Until now, most of these problems have been solved using the Microservices architecture, but what's next? What next approach should we apply where Microservices fail? In this presentation, we will overview modern approaches to application development with Reactive and Distributed architecture and see how Vert.x help to implement such solutions.
2. Orkhan Gasimov
Digital Transformation Architect @ GlobalLogic
15 years of software engineering;
training & mentorship;
author of trainings about:
Microservices;
Spring Cloud;
Akka;
2Speaker
41. Worker Verticles
Run on the worker pool & never executed concurrently
Verticles
DeploymentOptions options = new DeploymentOptions().setWorker(true);
vertx.deployVerticle("com.mycompany.MyOrderProcessorVerticle", options);
41
61. $ vertx run myVerticle -ha
Fail-Over
Vert.x Instance 1 Vert.x Instance N
...
Verticle
61
62. $ vertx run myVerticle -ha
Fail-Over
Vert.x Instance 1 Vert.x Instance N
...
Verticle
62
63. $ vertx run myVerticle -ha
Fail-Over
Vert.x Instance 1 Vert.x Instance N
...
Verticle
63
64. $ vertx run myVerticle -ha -hagroup group-1
Groups
Group-1
Vert.x Instance 1 Vert.x Instance N
Group-2
Vert.x Instance 1 Vert.x Instance N
...
...
Verticle
Verticle
64
65. $ vertx run myVerticle -ha -hagroup group-1
Groups
Group 1
Vert.x Instance 1 Vert.x Instance N
Group 2
Vert.x Instance 1 Vert.x Instance N
...
...
Verticle
Verticle
65
66. $ vertx run myVerticle -ha -hagroup group-1
Groups
Group 1
Vert.x Instance 1 Vert.x Instance N
Group 2
Vert.x Instance 1 Vert.x Instance N
...
...
Verticle
Verticle
66
78. ...
//Async get
asyncMap.put("foo", "bar", resPut -> {
if (resPut.succeeded()) { /*success*/ } else { /*fail*/ }
});
//Async put
asyncMap.get("foo", resGet -> {
if (resGet.succeeded()) {
Object val = resGet.result();
} else {
//fail
}
});
Maps 78
79. sd.getLock("mylock", res -> {
if (res.succeeded()) {
Lock lock = res.result();
// 5 seconds later we release the lock so someone else can get it
vertx.setTimer(5000, tid -> lock.release());
} else {
// Something went wrong
}
});
Locks 79
80. sd.getLock("mylock", res -> {
if (res.succeeded()) {
Lock lock = res.result();
// 5 seconds later we release the lock so someone else can get it
vertx.setTimer(5000, tid -> lock.release());
} else {
// Something went wrong
}
});
sd.getLockWithTimeout("mylock", 10000, res -> {
if (res.succeeded()) {
Lock lock = res.result();
} else {
// Failed to get lock
}
});
Locks 80
81. sd.getCounter("mycounter", res -> {
if (res.succeeded()) {
Counter counter = res.result();
} else {
// Something went wrong!
}
});
Counters 81
87. HttpServer server = vertx.createHttpServer();
Router router = Router.router(vertx);
Web Server 87
88. HttpServer server = vertx.createHttpServer();
Router router = Router.router(vertx);
router.post("/entity/:id").handler(routingContext -> {
// This handler will be called for every request
HttpServerResponse response = routingContext.response();
response.putHeader("content-type", "text/plain");
// Write to the response and end it
response.end("Hello World from Vert.x-Web!");
});
Web Server 88
89. HttpServer server = vertx.createHttpServer();
Router router = Router.router(vertx);
router.post("/entity/:id").handler(routingContext -> {
// This handler will be called for every request
HttpServerResponse response = routingContext.response();
response.putHeader("content-type", "text/plain");
// Write to the response and end it
response.end("Hello World from Vert.x-Web!");
});
server.requestHandler(router::accept).listen(8080);
Web Server 89
114. • Publish & Discover
• HTTP Endpoints
Service Discovery
Sales
Accounting
WarehouseUsers
Stores
HTTP
DB
SQL
114
115. • Publish & Discover
• HTTP Endpoints
• Data Sources
Service Discovery
Sales
Accounting
WarehouseUsers
Stores
HTTP
DB
SQL
115
116. • Publish & Discover
• HTTP Endpoints
• Data Sources
• Event Bus Services
Service Discovery
Sales
Accounting
WarehouseUsers
Stores
HTTP
DB
SQL
116
117. • Publish & Discover
• HTTP Endpoints
• Data Sources
• Event Bus Services
• Anything you can imagine
Service Discovery
Sales
Accounting
WarehouseUsers
Stores
HTTP
DB
SQL
117
125. CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
new CircuitBreakerOptions()
.setMaxFailures(5) // number of failure before opening the circuit
.setTimeout(2000) // consider a failure if the operation does not succeed in time
.setFallbackOnFailure(true) // do we call the fallback on failure
.setResetTimeout(10000) // time spent in open state before attempting to re-try
);
Circuit Breaker 125
126. CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
new CircuitBreakerOptions()
.setMaxFailures(5) // number of failure before opening the circuit
.setTimeout(2000) // consider a failure if the operation does not succeed in time
.setFallbackOnFailure(true) // do we call the fallback on failure
.setResetTimeout(10000) // time spent in open state before attempting to re-try
);
breaker.execute(future -> {
// future.complete(“success")
// future.fail("cause")
}).setHandler(ar -> {
// Get the operation result.
});
Circuit Breaker 126
127. CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
new CircuitBreakerOptions()
.setMaxFailures(5) // number of failure before opening the circuit
.setTimeout(2000) // consider a failure if the operation does not succeed in time
.setFallbackOnFailure(true) // do we call the fallback on failure
.setResetTimeout(10000) // time spent in open state before attempting to re-try
);
breaker.executeWithFallback(future -> {
// future.complete(“success")
// future.fail("cause")
}, th -> {
// Fallback
return "Hello";
}).setHandler(ar -> {
// Get the operation result.
});
Circuit Breaker 127
158. Reactive & Distributed
Event Bus
Handler Handler Handler Handler Handler Handler
Server 1 Server 2 Server 3 Server N...
158
159. Reactive & Distributed
Module ModuleModule
Event Bus
Handler Handler Handler Handler Handler Handler
Server 1 Server 2 Server 3 Server N...
159
160. Reactive & Distributed 160
Bridged
Apps
Data
Access
Metrics
External
Apps
IoT
Devices
etc.
Module ModuleModule
Event Bus
Handler Handler Handler Handler Handler Handler
Server 1 Server 2 Server 3 Server N...
161. Reactive & Distributed 161
Bridged
Apps
Data
Access
Metrics
External
Apps
IoT
Devices
etc.
Module ModuleModule
Event Bus
Handler Handler Handler Handler Handler Handler
Server 1 Server 2 Server 3 Server N...
162. • Java
• JavaScript
• Groovy
• Ruby
• Ceylon
• Scala
• Kotlin
Polyglot 162
Bridged
Apps
Data
Access
Metrics
External
Apps
IoT
Devices
etc.
Module ModuleModule
Event Bus
Handler Handler Handler Handler Handler Handler
Server 1 Server 2 Server 3 Server N...
163. • JavaScript
• Event bus integration over SockJS for browser-based & node.js apps.
Polyglot 163
Bridged
Apps
Data
Access
Metrics
External
Apps
IoT
Devices
etc.
Module ModuleModule
Event Bus
Handler Handler Handler Handler Handler Handler
Server 1 Server 2 Server 3 Server N...