Describe the architecture you use for Java web applications? [closed]

Let's share Java based web application architectures!

There are lots of different architectures for web applications which are to be implemented using Java. The answers to this question may serve as a library of various web application designs with their pros and cons. While I realize that the answers will be subjective, let's try to be as objective as we can and motivate the pros and cons we list.

Use the detail level you prefer for describing your architecture. For your answer to be of any value you'll at least have to describe the major technologies and ideas used in the architecture you describe. And last but not least, when should we use your architecture?

I'll start...

Overview of the architecture

We use a 3-tier architecture based on open standards from Sun like Java EE, Java Persistence API, Servlet and Java Server Pages.

  • Persistence
  • Business
  • Presentation

The possible communication flows between the layers are represented by:

Persistence <-> Business <-> Presentation

Which for example means that the presentation layer never calls or performs persistence operations, it always does it through the business layer. This architecture is meant to fulfill the demands of a high availability web application.


Performs create, read, update and delete (CRUD) persistence operations. In our case we are using (Java Persistence API) JPA and we currently use Hibernate as our persistence provider and use its EntityManager.

This layer is divided into multiple classes, where each class deals with a certain type of entities (i.e. entities related to a shopping cart might get handled by a single persistence class) and is used by one and only one manager.

In addition this layer also stores JPA entities which are things like Account, ShoppingCart etc.


All logic which is tied to the web application functionality is located in this layer. This functionality could be initiating a money transfer for a customer who wants to pay for a product on-line using her/his credit card. It could just as well be creating a new user, deleting a user or calculating the outcome of a battle in a web based game.

This layer is divided into multiple classes and each of these classes is annotated with @Stateless to become a Stateless Session Bean (SLSB). Each SLSB is called a manager and for instance a manager could be a class annotated as mentioned called AccountManager.

When AccountManager needs to perform CRUD operations it makes the appropriate calls to an instance of AccountManagerPersistence, which is a class in the persistence layer. A rough sketch of two methods in AccountManager could be:

public void makeExpiredAccountsInactive() {
    AccountManagerPersistence amp = new AccountManagerPersistence(...)
    // Calls persistence layer
    List<Account> expiredAccounts = amp.getAllExpiredAccounts();
    for(Account account : expiredAccounts) {
public void makeAccountInactive(Account account) {
    AccountManagerPersistence amp = new AccountManagerPersistence(...)
    amp.storeUpdatedAccount(account); // Calls persistence layer

We use container manager transactions so we don't have to do transaction demarcation our self's. What basically happens under the hood is we initiate a transaction when entering the SLSB method and commit it (or rollback it) immediately before exiting the method. It's an example of convention over configuration, but we haven't had a need for anything but the default, Required, yet.

Here is how The Java EE 5 Tutorial from Sun explains the Required transaction attribute for Enterprise JavaBeans (EJB's):

If the client is running within a transaction and invokes the enterprise bean’s method, the method executes within the client’s transaction. If the client is not associated with a transaction, the container starts a new transaction before running the method.

The Required attribute is the implicit transaction attribute for all enterprise bean methods running with container-managed transaction demarcation. You typically do not set the Required attribute unless you need to override another transaction attribute. Because transaction attributes are declarative, you can easily change them later.


Our presentation layer is in charge of... presentation! It's responsible for the user interface and shows information to the user by building HTML pages and receiving user input through GET and POST requests. We are currently using the old Servlet's + Java Server Pages (JSP) combination.

The layer calls methods in managers of the business layer to perform operations requested by the user and to receive information to show in the web page. Sometimes the information received from the business layer are less complex types as String's and integers, and at other times JPA entities.

Pros and cons with the architecture


  • Having everything related to a specific way of doing persistence in this layer only means we can swap from using JPA into something else, without having to re-write anything in the business layer.
  • It's easy for us to swap our presentation layer into something else, and it's likely that we will if we find something better.
  • Letting the EJB container manage transaction boundaries is nice.
  • Using Servlet's + JPA is easy (to begin with) and the technologies are widely used and implemented in lots of servers.
  • Using Java EE is supposed to make it easier for us to create a high availability system with load balancing and fail over. Both of which we feel that we must have.


  • Using JPA you may store often used queries as named queries by using the @NamedQuery annotation on the JPA entity class. If you have as much as possible related to persistence in the persistence classes, as in our architecture, this will spread out the locations where you may find queries to include the JPA entities as well. It will be harder to overview persistence operations and thus harder to maintain.
  • We have JPA entities as part of our persistence layer. But Account and ShoppingCart, aren't they really business objects? It is done this way as you have to touch these classes and turn them into entities which JPA knows how to handle.
  • The JPA entities, which are also our business objects, are created like Data Transfer Objects (DTO's), also known as Value Objects (VO's). This results in an anemic domain model as the business objects have no logic of their own except accessor methods. All logic is done by our managers in the business layer, which results in a more procedural programming style. It's not good object oriented design, but maybe that's not a problem? (After all object orientation isn't the only programming paradigm which has delivered results.)
  • Using EJB and Java EE introduces a bit of complexity. And we can't use purely Tomcat (adding an EJB micro-container isn't purely Tomcat).
  • There are lots of issues with using Servlet's + JPA. Use Google for more information about these issues.
  • As the transactions are closed when exiting the business layer we can't load any information from JPA entities which is configured to be loaded from the database when it's needed (using fetch=FetchType.LAZY) from inside the presentation layer. It will trigger an exception. Before returning an entity containing these kinds of fields we have to be sure to call the relevant getter's. Another option is to use Java Persistence Query Language (JPQL) and do a FETCH JOIN. However both of these options are a little bit cumbersome.

Asked by: Kimberly820 | Posted: 28-01-2022

Answer 1

Ok I'll do a (shorter) one:

  • Frontend : Tapestry (3 for older projects, 5 for newer projects)
  • Business layer: Spring
  • DAO's : Ibatis
  • Database : Oracle

We use Sping transaction support, and start transactions upon entering the service layer, propagating down to the DAO call's. The Service layer has the most bussines model knowledge, and the DAO's do relatively simple CRUD work.

Some more complicated query stuff is handled by more complicated queries in the backend for performance reasons.

Advantages of using Spring in our case is that we can have country/language dependant instances, which are behind a Spring Proxy class. Based on the user in the session, the correct country/language implementation is used when doing a call.

Transaction management is nearly transparent, rollback on runtime exceptions. We use unchecked exceptions as much as possible. We used to do checked exceptions, but with the introduction of Spring I see the benefits of unchecked exceptions, only handling exceptions when you can. It avoids a lot of boilerplate "catch/rethrow" or "throws" stuff.

Sorry it's shorter than your post, hope you find this interesting...

Answered by: Lily425 | Posted: 01-03-2022

Answer 2

Ideal Java Based Web Development Technologies Today.

Web Layer :


RESTFul Web Controller/Action/Request Processing Layer :

Play Framework

Business Logic/Service Layer:

Use Pure Java Code as long as possible. One can do fusion of web services here.

XML/JSon Data Transformation Layer :

XMLTool(Search On Google Code),JSoup,Google GSon,XStream,JOOX (Search On Google Code)

Persistence Layer :

CRUD : JPA or SienaProject or QueryDSL / Complex Queries : JOOQ,QueryDSL

Answered by: Anna754 | Posted: 01-03-2022

Answer 3

Here's my 5 cents


Android, Angular.JS WebClient, OAUTHv2


REST, Jersey (JAX-RS), Jackson (JSON de-/serialisation), DTO-objects (different from business logic models)

Business Logic

Spring for DI and Event handling. DDD-ish approach of model objects. Longer running jobs are offloaded with SQS in worker-modules.


Repository model with Spring JDBC-templates to store Entities. Redis (JEDIS) for Leaderboards, using Ordered Lists. Memcache for Token Store.


MySQL, Memcached, Redis

Answered by: Adrian518 | Posted: 01-03-2022

Answer 4

What we have followed in our project is :

Front end Technology

  • AngularJS
  • HTML5
  • css3
  • Javascript
  • Bootstrap 3


  1. REST
  5. Jackson
  6. spring security

Business Logic


  • SPRING data MongoDB

Data base

  • MongoDB

Server (For caching)

  • redis

Answered by: Aida587 | Posted: 01-03-2022

Answer 5

We are still using the usual Struts-Spring-Hibernate stack.

For future apps, we are looking into Spring Web Flow + Spring MVC + Hibernate or Spring + Hibernate + Web Services with Flex front end.

A distinct characteristic of our architecture is modularization. We have a number of modules, some starting with 3 to max 30 tables in the database. Most of modules consist of business and web project. Business project holds business and persistence logic while web holds presentation logic.
On logical level, there are three layers: Business, Persistence and Presentation.
Presentation depends on Business and Persistence.
Persistence depends on Business.
Business does not depend on other layers.

Most of business projects have three types of interfaces (note: not GUI, it is a programatic java interface layer).

  1. Interface that presentation is using as a client
  2. Interface that other modules are using when they are the client of the module.
  3. Interface that can be used for administrative purposes of the module.

Often, 1 extends 2. This way, it is easy to replace one implementation of module with another. This helps us adopt to different clients and integrate more easily. Some clients will buy only certain modules and we need to integrate functionality they already have. Since interface and implementation layer are separated, it is easy to roll out ad-hock module implementation for that specific client without affecting dependant modules. And Spring Framework makes it easy to inject different implementation.

Our business layer is based on POJOs. One tendency I am observing is that these POJOs resemble DTOs. We suffer from anaemic domain model. I am not quite sure why is this happening but it can be due to simplicity of problem domain of many of our modules, most of the work is CRUD or due to developers preferring to place logic somewhere else.

Answered by: Aida546 | Posted: 01-03-2022

Answer 6

Here is one more web architecture I have worked on:

One major requirement was the application should support mobiles/other devices. The application should also be extensible or flexible to changes in technology choices.

Presentation Tier:

  • JSP/JQuery (Client-side MVC)
  • Native Android
  • Native iPhone
  • Mobile web (HTML5/CSS3/Responsive design)

  • Spring REST Controllers (Can change to JAX-RS)

Business Service Tier:

Spring @Service (Can change to Stateless EJB)

Data Access Tier:

Spring @Repository (Can change to Stateless EJB)

Resource Tier:

Hibernate(JPA) entities (Can change to any ORM)

You can find more information on the book which follows this architecture here.

Answered by: Roland129 | Posted: 01-03-2022

Answer 7

IMHO, most of us have a common denominator. Atleast in the back-end, we have some form of IOC/DI container and a persistence framework. Personally I use Guice and Mybatis for this. The differences are in how we implement the view/UI/presentation layer. There are 2 major options here (may be more) .. Action based (URLs mapped to controllers) and component based. Currently am using component based presentation layer (using wicket). It perfectly mimics a desktop environment where I use components and events as opposed to URLs and controllers. Am currently looking for a reason why I should migrate to this URL-controller kind of architecture (that's how I ended up on this page). Why the hype about RESTful and Stateless architectures.

To answer this question in short: I write stateful web applications using a component oriented framework on top of Guice IOC container and put data in relational database using Mybatis.

Answered by: Gianna719 | Posted: 01-03-2022

Answer 8

A bit different, and I would claim more modular java architecture here. We have:

  1. Spring WS/Rest/JSP front end
  2. Spring MVC for business service logic, containing presentation layer logic as well as Spring transactions
  3. Component service communication interface, looked up through EJB by business services. EJBs set their own transaction boundaries that are able to join Spring transactions.
  4. Component service implementations, again Spring components
  5. Integration layer, MyBatis for database integrations, Spring WS for web service integrations, other integration techonologies for other services
  6. Mainframes, databases, other services at other servers...

In addition to the above, we have the shared library modules which is common functionality provider for all srevices.

Use of different layers allows us full decoupling and the modularity we need. We are also able to fully utilize the power of Java EE as well as Spring. Nothing prevents us from using JSF, for example, for the front end if needed.

Compared to example architecture by OP, I think this can be described as having four main layers instead of three, albeit with a twist.

Answered by: Lucas662 | Posted: 01-03-2022

Answer 9

I've worked on projects that use that rigid manager pattern. Historically, I was a huge proponent of the rigid hierarchy where everything fit into a neat box. As I progress in my career I find it to be forced in a lot of cases. I believe that adopting a more agile mindset towards application design leads to a better product. What I mean by this creating a set of classes that solve the problem at hand. Rather than saying "Did you build a manager for this and that?"

The current project I'm working on is a web app with a combination of Spring MVC and RestEasy JSON/Ajax calls. On the server side embedded in our controllers is a sensible facade based data tier with JPA/Hibernate for direct Database access, some EJB access, and some SOAP based web service calls. Tying all this together is some custom java controller code that determines what to serialize as JSON and return to the client.

We spend almost no time attempting to create some unified pattern instead opting to adopt the "Worse is Better" idea of the Unix Design Philosophy. Being that its much better to color outside the lines and build something sensible, quickly than it is to build something that adheres to a bunch of strict design mandates.

Answered by: David910 | Posted: 01-03-2022

Answer 10

The components in Web Application Architecture include :

1 : Browser : Client interaction


2 : Internet

3 : Webserver

        Pages(Java render )

4 : Application Server

        App Webapp (Java interaction)
        Others WebApps

5 : Database Server

        Oracle, SQL, MySQL

6 : Data

Answered by: Alfred176 | Posted: 01-03-2022

Similar questions

architecture - How can I share common components between Java web applications?

Environment IDE: Netbeans 6.9 App Server: Glassfish 3 Frameworks: Spring, Hibernate, Struts 2 Problem I have 2 web applications. I want to share resources between them both - i.e. authentication form jsp and other assets (js - yui,jquery/images/css). I will be adding more web applications that will also require access to these common c...

Proven Java architecture for enterprise applications

A few years ago I was working on Java enterprise web applications. We used something like this as a common architecture: Hibernate for data access Business logic coded in simple class Session beans at the service layer (internal and external access) JSP/Servlet for web with no templating or similar framework used For the last few years, I was focused on MS and .NET.

architecture - Strategy to merge java applications in one

Situation : 2 small java applications both of them connecting to remote service and sending some data there (first application listens to local socket, process data, sends it for verification to remote service and process response; second application starts on scheduled time, process some data for database and send that data to remote service).The problem is that remote service allows only one connection (that connection i...

java - Best architecture for applications in GWT

I'm starting to study GWT now, and have a very general question, I could maybe teach myself with a little more experience, but I don't want to start it wrong, so I decided to ask you. I always develop using JSF, having separate packages for beans, controllers and managedbeans. However, as the GWT uses RPC, I will not have managedbeans, right? So, GWT automatically handles user session for me, or do I have t...

jakarta ee - Java enterprise architecture for delegating tasks between applications

In my environment I need to schedule long-running task. I have application A which just shows to the client the list of currently running tasks and allows to schedule new ones. There is also application B which does the actual hard work. So app A needs to schedule a task in app B. The only thing they have in common is the database. The simplest thing to do seems to be adding a table with a list of tasks and having ...

java - architecture - should I combine many ad-hoc applications to a single application?

My main goal is providing a search application written in jquery that is based on solr. (For those who unfamiliar with solr, just assume its a rest api that can return search result.) For this goal I wrote many small applications and servlets that each one does an ad-hoc task. For example: SearchApp - a jquery app in which an end user can perform searches. SolrProxy - A java servlet that plays a pro...

architecture - java: detect if 32 or 64 bit applications can be executed

i have an executable which is available for windows, *nix and mac in both 32bit and 64bit. So, my java application needs to detect the operating system and bit architecture of programms which can be run to know which one to start. i already searched for a solution to detect the bitness of the operating system, jvm or such but i really didnt find the only one function which will return either 32 or 64 on any arbitra...

architecture - Type-safe approaches for handling reference data in Java applications

For possibly no other good reason at this point in time other that 'we've always done it like this', how are new systems being architected to use reference data used to represent state codes? For example, a Case may have 2 valid states, 'Open' or 'Closed'. Historically I've seen many systems where these valid values would be stored in a database table containing this reference data, and referred to as a code type ...

java - How to determine build architecture (32bit / 64bit) with ant?

We have inherited an ant build file but now need to deploy to both 32bit and 64bit systems. The non-Java bits are done with GNUMakefiles where we just call "uname" to get the info. Is there a similar or even easier way to mimic this with ant?

.NET equivalent of modern Java web architecture

Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring MVC for the web tier, Spring for the "Service"/business-logic-layer and an ORM mapper such as Hibernate for persistence. What is the equivalent in .NET? I guess ASP.NET is used for the web tier and ADO.NET for persistence but what is the equivalent to Spring, i.e. what is used to wire transactions and components and such.

java - Architecture - Multiple web apps operating on the same data

I'm asking for a suitable architecture for the following Java web application: The goal is to build several web applications which all operate on the same data. Suppose a banking system in which account data can be accessed by different web applications; it can be accessed by customers (online banking), by service personal (mostly read) and by the account administration department (admin tool). These applications ...

java - What architecture? Distribute content building across a cluster

I am building an content serving application composing of a cluster of two types of node, ContentServers and ContentBuilders. The idea is to always serve fresh content. Content is fresh if it was built recently, i.e. Content.buildTime &lt; MAX_AGE. Requirements: *ContentServers will only have to lookup content and serve it up (e.g. from a distributed cache or similar), no waiting for anything to be...

java - Space-based architecture?

One chapter in Pragmatic Programmer recommends looking at a blackboard/space-based architecture + a rules engine as a more flexible alternative to a traditional workflow system. The project I'm working on currently uses a workflow engine, but I'd like to evaluate alternatives. I really feel like a SBA would be a better solution to our business problems, but I'm worried about a total lack of community support/user b...

java - Server architecture for a multiplayer game?

Performance of REST architecture for Java / C# messaging

I currently have an application that sends XML over TCP sockets from windows client to windows server. We are rewriting the architecture and our servers are going to be in Java. One architecture we are looking at is a REST architecture over http. So C# WinForm clients will send info using this. We are looking for high throughput and low latency. Does anyone have any performance metrics on this approach vers...

architecture - How do I organize my java packages in our web mvc project?

Do you have any good tips on how should i organize class packages for my java project? We are usually building web MVC projects and our structure is something like this* - all model classes* - all service classes* - service classes related to particular model class* - dao classes ...

Java Application Architecture Guide

Is there a Java Application Architecture Guide that is a counterpart of this: ?

java - JVM garbage collection and a paging memory architecture

In the recent 10 year when discussing java and/or garbage collection, the only performance penalty that I have not been able to defend is that garbage collection algorithms more or less breaks when running in a paged memory architecture, and parts of the heap is getting paged out. Unix systems (and especially Linux) agressively pages out memory that has not been touched for a while, and while that is good for your ...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)