Sunday, May 19, 2013

Layered architecture: The Dumb and the Dumber

by Saleh Najar

One of the basic and most prevalent logical application architectures in the Structure category is the Layered Architecture. I can argue that one cannot design a quality solution without using the Layered Architecture. How does a designer generally stack the layers or quickly evaluate a Layered Architecture for proper implementation?

Every Layered Architecture stacks single-responsibility layers above each other where the flow of control goes downwards. Among other attributes and the requirement that every layer should deal with only one concern, an additional important attribute of the Layered Architecture is that every layer should generally be "dumber" than the layer above it. Layers in the Layered Architecture must follow the pattern of "Dumb & Dumber" as a mnemonic I came up with to remind architects of this pattern.

One might ask "Dumber" in which context and relative to what? When I say "Dumber" I mean dumber in knowing the higher level objective or business functionality of the calling layer. For example, if a lower layer specializes in writing a record to a database, it should not know that what it is writing is actually the payment from a credit card transaction as part of paying an invoice. This knowledge is specific to the higher "smarter" layer.

All complete systems start with an abstraction, a high level objective that they must accomplish. When upper layers delegate to lower layers, by design, these layers must be "dumber" and deal with a specific detail or part of the "bigger picture" that they know how to do well. Think of it as managers and the workers in real life. The more work travels down the work hierarchy, the more it gets more detailed and the more the lower layers of workers are not aware of the high business objective started at top levels. Ironically, this is a sign of an "intelligent" Layered Architecture of good quality.

Contrast this with the Component-based Architecture where all components communicating are on the same level of "intelligence". But each component on its own has lower layers to do the "grunt" work for them.

We can safely say that a "good" Layered Architecture is an architecture where each layer is less abstract, more detail-oriented and "dumber" about the functional goal than the layer above it. Hence the "Dumb & the Dumber" menmonic :)