Pragmatic Java Application Design
I attended the 20th edition of the Devoxx Belgium conference in Antwerp.
I heard about beautiful examples of how to design complex software applications written in Java.
The solutions scale to hundreds of thousands of users, are resilient to network disruption, and use fancy libraries and tools.
The applications are deployed on cloud infrastructure and are available worldwide.
After the conference, I went to Ibiza for a family holiday. Our family enjoys prolonging the summer on this beautiful Balearic island.
The weather is Switzerland is typical for fall. Cold, misty, and often rainy.
I used the relaxed location to reflect the kind of applications I often develop for customers.
The application goal often is to digitalize an internal process or a more complex workflow involving customers and suppliers.
The product we have to develop has the following characteristics:
-
It is a web-based application. Customers and their IT departments do not want to install an application locally. Only a few users access the application through a tablet or a smartphone. I expect that mobile user numbers will increase in the future.
-
It has from a few dozens to a maximum of a few hundreds of parallel active users. The user interface should be responsive to reflect modern user interface expectation.
-
Persistent data is often a few tens of gigabytes.
-
It has few computational intensive algorithms.
-
It often has to produce various output documents for distribution. The preferred format is PDF.
A CRM system for a small company uses quite a small persistent storage. The marketing department has less than 10'000 prospects and less than 1'000'000 interactions. The company has at most 10'000 contracts and 1'000'000 invoices. We can assume each object is less than 10 KBytes. The size of the whole database is therefore around 20 GB. Modern servers can easily load this data in memory and provide lightning fast access to information. Please factor in the fact that quite a slice of this data is in the past and is very seldom accessed. The application will not need regular access to all the historical information. Most of the time the application only accesses active customers, contracts, and invoices issued in the current year. |
Modular Monolith
The good approach to design such a system is to use a modular monolith architecture [2].
The technologies I use are:
- Domain Driven Design
-
Is a good architecture approach to creating modular monoliths with object-oriented technologies [1, 2, 3, 4].
- Modern Java technology stack
-
Is probably the most effective stack for engineering maintainable solutions. Trained engineers are available. High-quality open source and commercial libraries are available to solve most requirements [1].
- EclipseStore and HyperSQL
-
Are cost-effective and stable approaches for persistence.
- Logging log4j2
-
Is a powerful and established logging approach for your productive systems.
- Monitoring with Micrometer
-
Is an industry standard to monitor your productive solutions on premises or in the cloud.
- Vaadin, SO Charts
-
Is a Java-based approach to creating modern user interfaces. {ref-vaadin} empowers developers to use one technology stack for the whole application.
- PDF Box
-
Is a powerful library to generate your PDF output documents.
- FacturX and Swiss QR Code
-
Are used to create compliant invoices in Europe and Switzerland.
Limit the number of external libraries you are using in your products. Each additional framework increases maintenance costs and slows down your innovation progress. Java open-source projects are often laggards in adopting modern Java constructs.
The application could have a huge success and be sold as a product to customers. You must now support thousands of concurrent users and more persistent data.
The following changes are needed:
-
Split a modular monolith into a set of services.
-
Move to PostreSQL database.
-
Shard your application services and data either geographically or per customer groups.
The user interface written with Vaadin currently scales up to around ten thousand concurrent users for one server. If you have more users, you must create shards for your application. This approach will only scale for around a hundred thousand concurrent users. Honestly, I never created an application with more than eight thousand concurrent users. Products with more parallel users are seldom in Europe. |
Lessons Learnt
We are professional engineers. Form should follow function.
The huge majority of digital products we build do not need fanciful and expensive technologies.
We should build solid products [5]. Evolutive architecture principles [6, 7] help us to scale later.
Beware that if your market grows exponentially, you will have to rewrite your solution.
This approach is the best for your company and your cash flow.
Once your product is successful and attracts swarms of customers, you will better understand your customers and have the necessary budget to create a truly complex solution.
Track new technologies. Evaluate their adequacy for your organization and products.
I am currently evaluating Development Containers. It has the potential to simplify the setup of a development environment for a team. The approach also solves the maintenance nightmare to support multiple development environments for older product versions.
Links
-
[1 ] Monolith First Martin Fowler. 2015.
-
[2] Modular Monoliths Are the new Graal Marcel Baumann. 2022.
-
[3] Behavior Driven Design Marcel Baumann. 2022.
References
[1] V. Vernon, Domain-Driven Design Distilled. Addison-Wesley Professional, 2016 [Online]. Available: https://www.amazon.com/dp/B01JJSGE5S/
[2] V. Vernon, Implementing Domain driven Design. Addison-Wesley Professional, 2012 [Online]. Available: https://www.amazon.com/dp/B00BCLEBN8
[3] S. Hofer and H. Schwentner, Domain Storytelling. Pearson Education, Limited, 2021 [Online]. Available: https://www.amazon.com/dp/B099ZNXCJT
[4] E. Evans, Domain-driven design. Addison-Wesley, 2004 [Online]. Available: https://www.amazon.com/dp/0321125215
[5] D. Farley, Modern Software Engineering. Pearson Education, Limited, 2022 [Online]. Available: https://www.amazon.com/dp/B09GG6XKS4
[6] N. Ford, R. Parsons, and P. Kua, Building Evolutionary Architectures: Automated Software Governance, Second. O’Reilly Media, 2023 [Online]. Available: https://www.amazon.com/dp/B0BN4T1P27
[7] M. Erder, P. Pureur, and E. Woods, Continuous architecture in practice, First. Addison-Wesley, 2021 [Online]. Available: https://www.amazon.com/dp/B08ZRTQGLJ