Sunday, September 6, 2009

What Is The Difference Between A Layer & A Tier

When talking about software architecture, sometimes we hear the use of software layers and tiers used interchangeably. Can these terms really be used interchangeably? In other words, is a tier the same as a layer?

Architectural Layers
Layering, a structural architectural pattern, is the act of creating layers where each layer contains components that are all on the same level of abstraction. It is a core universal and logical design activity. The bottom layers are more concrete then the top layers. The higher you go in the layer stack, the higher the level of abstraction.

The higher in the layer stack, the less components are usually present. So if we were to visualize this layering logical structure, it will look like a pyramid or a triangle more than a vertical pipe.

Another important principle in the layering architectural pattern is that the lower layers are agnostic to who is calling them. They are highly reusable.

The Layers architectural pattern permeates everything in nature and anything that is well-built by humans. You always have the concrete workers at the bottom who do the detailed work, then you have a layer of controllers above them, then another layer of high level controllers and they repeat until you reach the top of the pyramid where a single responsibility or purpose is started. Optimally, this top purpose should be a use case or a business process that rolls down the layers for execution.

Architectural Tiers
Organizing a system into tiers is an architectural deployment pattern. This means that it has to do with how the architect physically organizes the system by assigning components to physical machines.

Why do we organize a system into separate physical tiers? Well, for many reasons. The main reason is scalability where we can scale out by adding more machines to get better performance for heavy loads. Another reason is security where sometimes we want to keep a certain layer on the perimeter and keep other layers secure within the internal network. Yet another reason is reusability where we might want to reuse the functionality of a certain layer from many different places to save on cost and keep the system consistent and easier to maintain/control.

Usually, layers are mapped to tiers. For example, we can assign the presentation layer to a perimeter machine or server that runs a web server while keeping the business layer secure inside and also usable by internal rich clients.

As you can see, tiers and layers are totally different. Layers are logical and a structural architectural pattern while Tiers are a physical and a deployment architectural pattern. However, they work nicely together.