Comparison
MiddlewarevsPipes and filters
Middleware
each function takes the next one and returns a new one, so authentication wrapped logging wrapped the actual handler.
A composable wrapper around a handler that can act before it, after it, or instead of it, stacked into a pipeline. It is the decorator pattern written as functions and assembled as a chain of responsibility, which is why it is the shape every web framework converged on independently. Its recurring difficulty is order: authentication before rate limiting and rate limiting before authentication are different products.
Full entry →Pipes and filters
each stage takes one thing and returns another, knows nothing about its neighbours, and you reordered two of them safely.
Decomposing processing into independent stages connected by a uniform channel, so each stage transforms and passes along. Unix pipelines, compilers, ETL jobs and stream processors are all this shape, and its virtue is that stages compose, reorder and parallelise because they share only the data format. The constraint is that shared format: anything a stage needs that the pipe does not carry has to be smuggled, and that is where the design breaks down.
Full entry →