Pipe and filter architecture

Also known as: pipes and filters

On this page 7

Pipe and filter architecture is an architectural style in which a system is decomposed into independent processing components called filters, each of which reads a stream of data, transforms it and writes the result to an output, with pipes carrying data between filters. In software architecture, the style is also known as pipes and filters, and it is the classic model behind Unix command lines, compilers, media encoders and modern data pipelines.

The style favors composition over coordination: no filter knows which component produced its input or which one consumes its output. That ignorance is the source of both its main strength, easy recombination and reuse, and its main weakness, difficulty with interactive or stateful behavior.

How pipes and filters move data through a system

A pipe and filter system works by passing data incrementally through a chain of transformations, where each filter performs one well-defined operation. A filter consumes input records, bytes or messages, applies its logic and emits output, often before the whole input has arrived. This incremental processing lets several filters run concurrently, so a long chain behaves like an assembly line rather than a sequence of batch jobs.

Pipes are the connectors that buffer and transport data. In an operating system, a pipe is a kernel buffer between two processes; in a library, it may be an in-memory queue, an iterator or a reactive stream; in a distributed system, it may be a message broker topic or a network socket. The pipe decouples the speed of producer and consumer and usually enforces first-in, first-out ordering.

The following table lists the structural elements and the responsibility of each.

ElementResponsibilityTypical implementation
Data sourceProduces the initial streamFile reader, sensor, HTTP endpoint
FilterTransforms, enriches or drops dataProcess, function, container, stream operator
PipeBuffers and transports data between filtersKernel pipe, queue, broker topic
Data sinkConsumes the final resultDatabase writer, file, display
Pipeline configurationDefines which filters connect to whichShell command, DAG definition, build script
Core elements of the style

Types of filters and pipeline topologies

Filters differ in how they obtain and release data, and the distinction affects concurrency and buffering. An active filter runs its own thread or process and pulls or pushes data itself, whereas a passive filter is invoked by a neighbor, for example as a function call in a pull-based iterator chain.

The next table summarizes common filter categories by the operation they perform.

Filter typeOperationExample
TransformerChanges the format or content of each itemConverting CSV rows to JSON
Tester or selectorPasses or drops items by a conditionRemoving records with missing fields
EnricherAdds data from another sourceAttaching a customer name to an order
AggregatorCombines several items into oneComputing a sum per hour
SplitterDivides one item into severalBreaking a document into sentences
Filter categories by operation

The simplest topology is a linear pipeline, in which each filter has one input and one output. Real systems often form a directed acyclic graph in which streams fork to several consumers or merge from several producers. Feedback loops are possible but undermine the predictability that makes the style attractive, so most designs avoid them.

Pipe and filter architecture is easiest to understand next to neighboring styles in the same field. It shares loose coupling with event-driven architecture, but its data flow is fixed by configuration rather than discovered through subscriptions, and it emphasizes transformation rather than notification.

StyleUnit of compositionControl of flowBest fit
Pipe and filterTransforming filterStatic chain or graphStreaming and batch transformation
Layered architectureLayer with a service interfaceRequests travel down and back upBusiness applications
Event-driven architectureEvent producer and consumerDynamic subscriptionsReactive, loosely related reactions
MicroservicesIndependently deployed serviceSynchronous or asynchronous callsLarge organizations and domains
Batch sequentialProgram run to completionEach step waits for the full outputPeriodic bulk jobs
Comparison with neighboring styles

The batch sequential style is the closest relative. The difference lies in incremental versus complete hand-over: a batch step writes its entire output before the next one starts, whereas a true pipe and filter chain lets data flow while upstream work continues.

Where pipe and filter architecture is used

The style fits any problem that can be described as a series of transformations on a data stream. Unix shells made it famous: a command such as grep error app.log | sort | uniq -c composes three small programs that know nothing about each other. Compilers follow the same pattern with lexing, parsing, optimization and code generation stages.

  • Extract, transform, load jobs and streaming data platforms that clean and route records.
  • Media processing, where decoding, scaling, filtering and encoding form a chain of filters.
  • Signal and image processing, including audio effects and computer vision preprocessing.
  • Continuous integration pipelines that build, test, scan and package code in fixed stages.
  • Web server middleware chains that authenticate, log and compress each request.

The following decision table helps decide whether the style suits a given requirement.

SituationRecommendationReason
Stable sequence of transformationsUse pipes and filtersStages map directly to filters
High data volume with streaming inputUse pipes and filtersIncremental processing keeps memory low
Heavy user interaction and shared statePrefer a layered or component designFilters cannot easily share state
Strict transactional consistencyAdd careful design or avoidPartial results may already be emitted
When to choose the style

Limitations, risks and design mistakes

The style has well-known costs that experienced architects weigh early. Serialization overhead appears when every filter must parse and re-encode data in a common format, and that cost can dominate run time in long chains of small filters.

Error handling is harder than in a call-and-return design, because a failure deep in the chain cannot simply return an exception to the original caller. Robust pipelines therefore define dead-letter outputs, retries and idempotent filters. Backpressure is another concern: when a slow filter cannot keep up, the pipe must block the producer, drop data or grow its buffer without limit.

MistakeConsequenceRemedy
Filters that share hidden stateLoss of independence and reusePass all needed data in the stream
Unbounded pipe buffersMemory exhaustion under loadApply bounded queues and backpressure
Too many tiny filtersOverhead exceeds useful workMerge trivial steps into one filter
No error channelSilent data lossRoute failures to a dead-letter sink
Common mistakes and remedies

In everyday language

Imagine a car wash with several stations in a row. One station soaks the car, the next scrubs it, another rinses it and the last one dries it. Each station does one job only and does not care what happens before or after. The conveyor belt moves cars from one station to the next.

Pipe and filter architecture builds software the same way. The stations are filters, the conveyor belt is the pipe and the cars are pieces of data. The key idea is that small, independent steps can be rearranged like stations on a line, which makes the system easy to extend and understand.

Seen in the real world

A logistics company receives about two million GPS readings per hour from delivery vans. The engineering team builds a pipeline of five filters: a parser converts raw messages to records, a validator drops readings with impossible coordinates, an enricher attaches the route number, an aggregator computes average speed per five-minute window and a writer stores the results for the dispatch dashboard.

Each filter runs as a separate container connected by broker topics. When the team later needs to detect unusual stops, it adds one new filter after the enricher without touching the other four. The result is a new feature delivered in days, while the parser and validator continue to serve the existing dashboard unchanged.