Lessons in scalability
In Theory and practice in the J2EE world I paused to consider the gap between what we can read in clever books about J2EE and what happens in practice. A presentation about eBay’s system architecture gave a practical view. Nati Shalom opened a related discussion, Why most large-scale Web sites are not written in Java.
Nati Shalom started with data gathered from HighScalability, as shown in the following table.

The table shows LAMP (Linux, Apache, MySQL, PHP or Perl) as the preferred stack. It’s worth asking why. Nati rightly points out the difference between the requirements of web applications and mission-critical applications, which are typically built on the J2EE stack. He sees some common areas when it comes to scaling both kinds of application.
- caching at the data layer to minimize disk I/O
- aiming for horizontal partitioning
- minimizing distributed transactions
- easy parallelization at the application layer
The trouble with J2EE is that scalability is a somewhat abstract idea that runs through the specification and marketing material. From practical experience with the J2EE stack, I’d say servlets are about the only things that scale properly. To write a highly scalable application in J2EE, you have to leave out a lot of technologies.
Here are my tips for a middle-tier architecture that scales well.
- Stateless design and idempotent operations
- Local transactions
- Hibernate
- In-memory data grids
- Spring
A stateless design is the first prerequisite for scaling well because there’s no state to synchronize across the cluster. An application also needs some fault tolerance, which idempotent operations should provide. An operation’s result stays the same however many times you call it. Use local transactions because JTA brings no benefits with a single transaction participant and adds needless overhead.
Use Hibernate because it supports a transactional first-level cache and you can easily configure a high-performance second-level cache (Comparing Memcached and Ehcache Performance, thanks Kolesi!). It should also support horizontal partitioning. If you do need to hold state, use an in-memory data grid. A solution dedicated to scaling works better than application-server support. Finally, Spring lets you tie all of it together painlessly.
In short, you can write an application that scales well in J2EE. You just have to know how…
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio