This article will discuss the various architectures of Client-Server environments. Perhaps the most influential Client-Server environment is the Internet and its global users. With the increasing use of web applications, an examination of the best architecture to support web applications is timely. The architectural component of this discussion will focus on the underlying structures and schematics that best build web applications. Specifically, we will be discussing tier architecture, which is the breaking down of an application into logical chunks that are called Tiers. Tiers can exist on the same computer and be connected virtually or logically or on different machines.
The simplest examples of tier architecture are enumerated as 1-Tier, 2-Tier, and 3-Tier. 1-Tier Architecture is the simplest, single tier on single user, and is the equivalent of running an application on a personal computer. All the required component to run the application are located within it. User interface, business logic, and data storage are all located on the same machine. They are the easiest to design, but the least scalable. Because they are not part of a network, they are useless for designing web applications. 2-Tier Architectures supply a basic network between a client and a server.
For example, the basic web model is a 2-Tier Architecture. A web browser makes a request from a web server, which then processes the request and returns the desired response, in this case, web pages. This approach improves scalability and divides the user interface from the data layers. However, it does not divide application layers so they can be utilized separately. This makes them difficult to update and not specialized. The entire application must be updated because layers aren’t separated.
3-Tier Architecture is most commonly used to build web applications. In this model, the browser acts like a client, middle-ware or an application server contains the business logic, and database servers handle data functions. This approach separates business logic from display and data. But, it does not specialize functional layers. Its fine for prototypical or very simple web applications, but it doesn’t measure up to the complexity demanded of web applications.
The application server is still too broad, with too many functions grouped together. This reduces flexibility and scalability. N-Tier Architectures provide finer granularity, which provides more modules to choose from as the application is separated into smaller functions.
N-Tier and Example
Usually N-Tier Architecture begins as a 3-Tier model and is expanded. It provides finer granularity. Granularity is the ability of a system, in this case, an application, to be broken down into smaller components or granules. The finer the granularity, the greater the flexibility of a system. It can also be referred to as a system’s modularity. Therefore, it refers to the pulling apart of an application into separate layers or finer grains.
One of the best examples of N-Tier Architecture in web applications is the popular shopping-cart web application. The client tier interacts with the user through GUIs (Graphic User Interfaces) and with the application and the application server. In web applications, this client tier is a web browser. In addition to initiating the request, the web browser also receives and displays code in dynamic HTML (Hypertext Markup Language), the primary language of the World Wide Web. In a shopping cart web application, the presentation tier displays information related to such services as browsing merchandise, purchasing, and shopping cart contents. It communicates with other tiers by outputting results to the browser/client tier and all other tiers in the network.
This layer calls custom tags throughout the network and to other networks. It also calls database stored procedures and web services, all in the goal of providing a more sophisticated response. This layer glues the whole application together and allows different nodes to communicate with each other and be displayed to the user through the browser. It is located in the application server.
In N-Tier Architecture, the business logic tier is pulled out from the presentation tier and, as its own layer, it controls an application’s functionality by performing detailed processing. For example, in our shopping cart example, this tier completes credit card authorization and calculates things like shipping costs and sales tax. The tools used to encapsulate an application’s business logic into its own layer include web services, custom tags, and stored procedures.
The business tier can also be considered the integration layer. Encapsulation allows the application to communicate with the data tier or the business logic tier in a way that is intelligible to all nodes. Encapsulation is one of the principles of object-oriented programming (OOP) and refers to an object’s ability to conceal its data and methods. Encapsulated objects only publish the external interface so any user interacting with them only needs to understand the interface and can remain ignorant as to the internal specifications. This way a user can call all sorts of services into action by calling the custom tag without having to know the code details of what made communication or implementation possible. The services just have to be accessible in the custom tag library. Encapsulation in the integration tier also liberates the network from just one vendor. The integration tier allows N-Tier Architecture to be vendor independent. In the shopping cart example, the application may have a simple custom tag for searching inventory and providing the most up-to-date, detailed information.
The final application tier is the data tier. It usually consists of database servers. It keeps data neutral and independent from application servers or business logic. Giving data its own tier also improves scalability and performance. As it grows, it is easily moved to another, more powerful machine.
Applying N-Tier Architecture and Example
Let’s now apply N-Tier Architecture to our shopping cart example. In this example, we will demonstrate how sales tax is calculated and displayed. The presentation tier calls the business logic tier to perform computations on the data in the shopping cart to calculate total price. The business logic tier communicates with a database (data tier) to extract the sales tax amount based on the total price.
The business logic tier is able to communicate with the data tier through the integration tier. Through encapsulation, the integration tier is able to conceal the complexities of communication. It also retrieves the right tax rate and returns it to the business logic tier. The business logic tier completes its calculations. The presentation tier formats the response through HTML and forwards it to the client or web browser, where it is displayed to the user.
Benefits of N-Tier Architecture
There are many business benefits to N-Tier Architecture. For example, a small business can begin running all tiers on a single machine. As traffic and business increases, each tier can be expanded and moved to its own machine and then clustered. This is just one example of how N-Tier Architecture improves scalability and supports cost-efficient application building.
N-Tier model also make applications more readable and reusable. It reduces the amount of spaghetti code. Custom tag libraries and EJBs are easier to port to readable applications in well-maintained templates. Reusability multiplies developer productivity and improves application maintainability. It is an important feature in web applications.
N-Tier Architectures make application more robust because there is no single point of failure. Tiers function with relative independence. For example, if a business changes database vendors, they just have to replace the data tier and adjust the integration tier to any changes that affect it. The business logic tier and the presentation tier remain unchanged. Likewise, if the presentation layer changes, this will not affect the integration or data layer. In 3-Tier Architecture all the layers exist in one and affect each other. A developer would have to pick through the entire application code to implement any changes. Again, well-designed modules allow for applications or pieces of applications to be customized and used across modules or even projects. Reusability is particularly important in web applications.
As demonstrated N-Tier Architecture offers innovations in the standard Client-Server technology that spawned the Internet itself. It is but one of many web application frameworks. These are used to develop dynamic web sites, web applications or web services. They provide database access libraries, templates, and, as previously stated code re-use. Most web application frameworks follow the Model View Controller (MVC) which separate the user interface, the business rules and the data model.
They provide authentication and authorization to provide security. This allows the web server to restrict user access based on pre-determined criteria. Web application frameworks also provide a unified API (Application programming Interface). This allows web application to work with various databases without requiring any code change. These frameworks also maintain a web template system.
Finally, N-Tier Architecture helps developers build web applications because it allows developers to apply their specific skill to that part of the program that best suits their skill set. Graphic artists can focus on the presentation tier, while administrators can focus on the database tier.