§3.2.

What is layering?

Layering is a key design principle in software development and is especially important in internet programming. It is a technique for reducing the complexity of large systems.

Layering is a simple idea: divide the complex system into a hierarchy of layers. A layer depends only on the layer immediately below it, is depended upon only by the layer immediately above.

One way to think about a house is a series of layers: [1]

Roof

Walls

Foundation

The roof is held up by the walls. It doesn’t need to know about the foundation. It only depends on the walls.

The walls support the roof but depend on the foundation. It doesn’t matter whether the roof is made out of tin or tile. It doesn’t matter whether the foundation is deep or shallow.

The foundation must support the layers above, but the details of the roof (e.g., whether nails or glues are used) aren’t important to the foundation.

Layering appears throughout internet programming. For example, the tiers of a classic 3-tier architecture (this will be covered in Chapter 12):

Web browser

Web server

Database server

Or, for example, the three principal layers of enterprise applications:

Presentation logic (user interface logic)

Domain logic (business logic)

Persistence (database logic)

Or, even the layering of technologies used when you browse the web on your home computer:

Web browser

Graphics and networking libraries

Native operating system calls

Device drivers

Hardware circuitry

In this chapter, I will discuss two kinds of layering in two ways. First, a simple web server which uses Express as a dependency:

"Hello, World!" web server

Express

Node

Second, a more complex layering involved in a deep dive into handling an HTTP request:

Rendering engine

Browser engine

HTTP

TCP

DNS

UDP

IP


1. My apologies if you are a builder or civil engineer!