Skip to content

Commit c77abdf

Browse files
committed
blog post about Apiman 4 WIP
1 parent 830c9ba commit c77abdf

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
author: marc_savy
3+
date: 2025-05-12 16:00:00 BST
4+
tags: apiman, vert.x, apiman4, black parrot labs, dev diary, software architecture
5+
allow-uri-read: true
6+
---
7+
8+
== Apiman 4 Dev Diary: Hybrid Vert.x Async-Imperative Applications
9+
10+
Let's be honest, whilst async platforms are extremely performant, the programming, debugging, and maintenance of async code is more difficult than imperative programming. The situation has now become yet more nuanced with the arrival of the JVM's virtual threads.
11+
12+
// more
13+
14+
****
15+
💡 https://www.blackparrotlabs.io[Black Parrot Labs^] offers comprehensive enterprise support for Apiman.
16+
17+
If you depend on Apiman and want open source to be sustainable, consider working with us.
18+
19+
As the developers and maintainers of the platform, nobody knows Apiman better.
20+
21+
https://www.linkedin.com/feed/update/urn:li:activity:7327678940800598016/[This is adapted from Apiman founder Marc's post on LinkedIn^].
22+
****
23+
24+
A thought occurred to me while working on Apiman 4 at https://www.blackparrotlabs.io[Black Parrot Labs^]: even within the same codebase there are often large proportions of code which do not need high performance, as they are only used occasionally (e.g. only used at startup, cached, very occasional use, etc). Wouldn't it be nice to be able to hybridise your application and have greater architectural flexibility?
25+
26+
With Eclipse Vert.x 4 and 5, in combination with https://docs.oracle.com/en/java/javase/21/core/virtual-threads.html[Java's virtual threads^], you can now have that.
27+
28+
Let me give an example:
29+
30+
.Simplified Architectural Diagram
31+
image::/assets/images/blog/2025-05-12/arch.png[]
32+
33+
.Code Snippet
34+
image::/assets/images/blog/2025-05-12/snippet.png[]
35+
36+
Let's say we have a stockbroker service to buy your favourite meme stock.
37+
It consists of three components:
38+
39+
- "Stock Broker" is a used very frequently and has extremely intensive performance requirements. You don't want to miss out on your opportunity to lose your money very quickly, after all.
40+
41+
- "Users" and "Permissions" are used much less frequently, but have complex logic which can be burdensome to maintain as "pure" traditional async code.
42+
43+
So, how do we mix and match?
44+
45+
With the latest-and-greatest versions of Vert.x, we can run the Users and Permissions components as 'virtual thread verticles'.
46+
47+
This allows us to call `await()` on any asynchronous call/future, and block until the response is ready (or an exception thrown). Standard imperative patterns. In the background, Vert.x dispatches the call onto a virtual thread — but we don't need to worry about that.
48+
49+
Given its performance requirements,
50+
we implement "Stock Broker" as a standard verticle using our usual asynchronous patterns.
51+
When we need data from the Users and Permissions components, we interact over Vert.x's lightweight message bus,
52+
so it is never impacted by the alternative/blocking approach described above for Permissions, Users, etc.
53+
54+
I hope this makes sense; it lets us have the 'best of both worlds' and does not force us to use more challenging techniques on code that does not need it.
55+
56+
You can find more examples on the Vert.x website, and I included an annotated example on the second picture.
57+
58+
So, have any of you created Vert.x applications that are hybrids of virtual thread verticles and standard reactor verticles? I'd love to hear your thoughts!
59+
60+
(Incidentally, the performance of the virtual thread verticles seems excellent, so that probably pushes the needle even higher on which applications justify "real" async).
61+
62+
Thank you to Julien Viet, Julien Ponge, Clement Escoffier, Paulo Lopes, Thomas Segismont et al for your hard work on this. I see your names in the code frequently 😅.
63+
73 KB
Loading
482 KB
Loading

0 commit comments

Comments
 (0)