Large Enterprise Java Projects Architecture

Do you remember the old mainframe days? Users would enter data in the dumb terminals, and those terminals weren’t capable of anything else. All processing would happen in the Mainframe.

In comparison, today Netflix accounts for 31% of the North American Internet traffic and is heavily reliant on microservices. We have indeed come a long way!

The advent of Java, arguably one of the most powerful programming languages ever, has changed the enterprise application development landscape completely.

While Java with its’ rich array of features lets the Enterprise get its’ job done in a variety of ways, concerns of maintainability, manageability and need to have many releases throughout the year have prompted the projects teams to create various architectural models for the enterprise projects.

In this article, I will describe the five most popular Java app architecture the enterprise of today uses, with their pros and cons.

Layered (n-tier) architecture: the most common enterprise Java project architecture

 

n-tier-architecture1

Today’s enterprises have been storing their data using large ‘relational database management systems’ (RDBMS) and tables in these databases have a massive amount of corporate data. The layered architecture is the most common today because it’s built around data stored in these tables.

As you know, many of today’s Java enterprise apps are built using famous frameworks like Java Platform Enterprise Edition (Java EE), Drupal, and Express. These platforms themselves follow this layered architecture, and as a result, the applications follow this model too.

This enterprise Java applications architecture is designed so that the data enters the very top layer. The data then flows through the other layers, and finally reaches the database at the bottom of the layers. The different layers can, and usually do, have different tasks. One layer may check the data for consistency, and another may reformat the values to maintain a common standard in the application.

Download Our Project Specification Template

The Java developers have adopted this architecture in a significant manner, for e.g. most web frameworks employ the ‘Model-View-Controller’ (MVC) structure as a standard development approach. MVC is an example of layered Java app architecture. It’s common to find programmers experienced in specific layers, and teams organized according to the layers.

How does MVC work? The model layer sits just on top of the database and has the business logic. It also contains information about the kind of data the database holds. The view layer is at the top with possibly CSS, JavaScript, and HTML code. The controller is in the middle containing the various rules for transforming data traversing between the model and the view.

There are both pros and cons of the layered architecture. Following are some of the advantages:

  • It allows the project team the ‘separation of concerns’, i.e. each of the layers can concentrate on its’s role only. This architecture is hence easy to maintain and testing is easier. The project team can easily assign separate ‘roles’, and individual layers can be enhanced separately.
  • If the architect has properly separated the layers, then changes in one will not affect another layer. This makes it easy to execute projects requiring changes only to some specific functionalities.
  • Additional open layers can be created, for e.g. a ‘service layer’, and access can be customized.

Although the most common architecture, these can also several difficulties in managing this. For e.g.:

  • The architect must do a really good job of segregating tasks for different layers.
  • If the programmers don’t code factoring the separate roles according to the layer, the program can become a very unorganized one.
  • A significant portion of code is devoted to passing data between layers and has no other business logic. The overall program can become slow.
  • An architect joining the project team later will find it difficult to understand the architecture because of so many layers and will need to read all programs.
  • If good coordination in the team is absent, a developer can code skipping layers. This creates a program with complex interdependencies and that becomes hard to maintain.
  • Depending on the effectiveness of the implementation, this architecture may need complete redeployment of the application even due to small changes.

This is suitable for the following scenarios:

  1. A new app must be built and deployed quickly;
  2. Business apps that need to conform to the tradition IT department practices;
  3. The project team is inexperienced and understands only this model;
  4. The maintainability requirements are stringent, and testing should be easy in future.

Event-driven architecture for enterprise Java projects: For the apps that wait on data

event-driven

You have seen apps that are active only when there’s data for processing, and inert at other times. Many web apps waiting for human interaction are good examples, however, in the world of networking also, there are applications that wait for data to arrive.

In the event-driven architecture model, there is one central agent that accepts the input data. This architecture has separate modules for different functions, and the central agent directs the data to appropriate module. The word ‘event’ in the name refers to this handoff.

Take the example of a website that uses JavaScript. The mouse clicks and keystrokes by the user are events. In this case, the browser performs the role of the central agent. It collates all data inputs, even in the forms of mouse clicks or keystrokes, and sends a form of data only to the module that deals with that kind.

The modules will be inert if the input ‘event’ is not in their functional area, although the user may be continuing to input different kinds of data in the browser. This is the main difference with the layered architecture where all data must pass through all layers.

The advantages of the event-driven architecture are following:

  1. It’s suitable for chaotic environments, it adapts well to complexity.
  2. This model is highly scalable.
  3. When the app needs new functionalities, thus generating new kinds of events, this architecture can be easily extended to cover the new events.

There are also different complexities in this model, and the programmers must take care of them. For e.g.:

  1. If there are interdependent modules, then while the individual modules can be tested easily, testing the interactions between separate modules requires fully functioning test environment.
  2. There are instances when different module must handle the same event. In such cases, the error-handling requires complex programming.
  3. The project team must design fall-back options for the central agent, in case individual modules catering to certain events experience a failure.
  4. Some of the apps may have activities only in bursts. It’s possible that inputs arrive in bursts, and the central agent must have a mechanism for buffering of messages. The developers must factor this in, and it’s an overhead, which can slow down the app.
  5. This architecture requires a high volume of upfront work on the part of the data modelers and database designers. The events vary, they have different needs. Accordingly, the modules deal with different kinds of data, hence the data modelers have their task cut out when they aim to create a data structure for the entire app.
  6. The modules in this architecture are independent of each other, and it’s hard to maintain a consistent transaction-based mechanism.

This architecture is best for apps with UIs, for e.g. web apps. Also, apps involving individual data blocks interacting only select modules should use this architecture.

Microkernel architecture: One for high-usage tools

A microkernel is a small OS core that provides the foundation for modular extensions. The term is somewhat fuzzy, however, and there are a number of questions. The microkernel approach was popularized by its use in the Mach OS,which is now the core of the Macintosh Mac OS X operating system.

A microkernel is a small OS core that provides the foundation for modular extensions. The term is somewhat fuzzy, however, and there are a number of questions. The microkernel approach was popularized by its use in the Mach OS,which is now the core of the Macintosh Mac OS X operating system.

If you are a Java programmer, you have used the Eclipse integrated development environment (IDE), so have I. All Java developers have used it, and it’s a tool famous for doing a lot of routine tasks all by itself without the user even prompting for it.

You have seen how Eclipse opens the files, annotates those, edits the files while starting the background processor. Once the developers are done with the coding, they can click a button to compile their code. Eclipse uses a microkernel where all the routines for these basic repetitive operations are stored.

Read How We Helped a Marketing Company to Build a Back-Office Custom Ads Dashboard

Note that the Java compiler isn’t part of the microkernel, rather it’s just a bolt-on, running on top of the eclipse. You could take Eclipse and use it to code programs in other languages, and in such case, you will not use the Java compiler. However, you will use the basic routines.

In the microkernel architecture, basic routines are executed as part of the kernel. The other features may vary depending on the business the app is used for, and the project teams can just code them as bolt-on routines on top of the kernel. This is also called ‘plug-in architecture’.

The advantages are obvious. This is used in tools with heavy usage because it simplifies the common operations.

  • However, the developers using it as their Java application structure need to follow these best practices:
  • Determine carefully what the microkernel holds. It should only hold code that’s frequently used.
  • The plug-ins on top should have handshaking code so that the microkernel know that those are ready to work.
  • When several plug-ins have been installed and they all depend on the microkernel, it’s very hard to modify the microkernel independently. Often the plug-ins will need modifications, too.
  • When working with this architecture, the project team should have adequate expertise to decide the granularity of the kernel upfront. It’s nearly impossible to change it later.

In addition to high-usage tools, this architecture is also good for apps with a fixed set of core tasks, because the dynamic set of tasks can be accomplished using bolt-on routines and those can be modified frequently.

Microservices architecture: Build many small programs instead of a giant one

microservices

Look at the Netflix UI. The various interfaces, for e.g. to list your favorites, accounting information, the ratings you gave to films, are all different services. You can think of the Netflix website as one seamless collection of many smaller websites. The company uses microservices architecture.

This architecture allows the Java developers to build many smaller programs for different services, instead of having to build one giant program that does it all. A new feature will also require one new small program.

There are similarities with the event-driven or the microkernel architecture, however, in case of the microservices architecture the different tasks are truly separated. The demands for the different services are different, and the enterprise can run them from separate servers and scale up or down according to the demand.

For the enterprises with heavy consumer demands, this represents a significant advantage. For e.g. Netflix runs their content delivery and other tracking services on different servers. It helps them with scaling, and with 31% of the North American Internet traffic coming to them, they certainly need to scale.

There are important factors to consider when implementing the microservices architecture, for e.g.:

  • The services should be independent of each other.
  • This isn’t suitable for apps where tasks can’t be fully separated.
  • If a task is spread out between different microservices then performance may be sub-optimal.
  • A webpage with too many microservices may give an appearance to the user that some parts of the site are loading slower, and it can be confusing.

This architecture is good for websites with small separate components, or new web apps requiring rapid development of parts.

Space-based architecture: to address high load on the database

Websites built around a database function well when the database works well. However, under exacting conditions of high-load, the database can fail, it may not be able to keep writing log of every transaction. Along with the database, the website also fails.

To address this issue, the enterprise architects have come up with the concept of space-based architecture, where the processing logic, as well as the database, is partitioned into multiple servers. Individual horizontal shards of the database can function much better, and the web app benefits as well.

This enterprise architecture uses all ‘in-memory’ objects, and storing the information in RAM makes the app faster. This, while partitioning the storage and processing, makes for a simplification. This is also called ‘cloud architecture’.

However, there are the following disadvantages:

  • Computing operations spread out the entire database, for e.g. a statistical analysis involving the entire data, can become more complex. Such processes must be broken down into ‘subjobs’, distributed, and then finally aggregated.
  • Database loaded into RAM makes transaction support harder.
  • Testing the entire system is harder since enough load must be generated.
  • There are multiple nodes, and hence multiple copies of data. In this circumstance, caching the data is harder, due to the risk of corrupting the data.

This is good for high-volume, but low-value, data. Social networks can make good use of this enterprise architecture. However, as I have mentioned, there are difficulties with developing good and safe caching, and data may occasionally be lost. This architecture is certainly not for the banks!

Do you want to learn more about these examples of Java project architectures? Here’s a good book for you, and it’s also free!  I also recommend this article.

Good luck creating your next large enterprise Java project!

Download Our Project Specification Template

Aran Davies

Aran Davies

Blockchain Expert | Developer | Writer | Photographer
Aran Davies