Skip to content

Pipe and Filter : Design Pattern

Anand Patel edited this page Nov 27, 2016 · 13 revisions

Pipe and Filters is architectural pattern in which a process consists of a series of steps to be followed in order to proceed the data, and the output of one step is the input of another step, Use pipe and filters when system requires series of actions to be executed against an object.

  • Each step is a called a filter component and the entire sequence of called the pipeline.
  • The filter components take a message as input, do some sort of transformation on it and then send it to the next filter component for further processing.

Pipeline is similar to chain of responsibility. The main difference is that in the chain, each "link" passes something to the next until one knows what to do with it, then the process stops. In pipeline, something is passed to every chain in the link and potentially modified with each pass. This is where "pipes and filters" come into play because one link may filter while other links in the pipe may add.

Examples

The most common implementations of a pipe and filter architecture are

  • Unix programs where the output of one program can be linked to the output of another program.
  • Processing XML via a series of XSLT transformations.
  • Compilers (lexical analysis, parsing, semantic analysis, optomization and source code generation)
  • ASP.Net Http Pipeline (Begin_Request, Authorize_Request, etc)
  • Command Line piping (ps -ax | grep Finder)

Real World Use Case

  • Batch processing,
  • ETL
  • Workflow, etc.

In many enterprise integration scenarios, a single event triggers a sequence of processing steps, each performing a specific function.

For example, let's assume a new order arrives in our enterprise in the form of a message.

  • One requirement may be that the message is encrypted to prevent eavesdroppers from spying on a customer's order.
  • A second requirement is that the messages contain authentication information in the form of a digital certificate to ensure that orders are placed only by trusted customers.
  • In addition, duplicate messages could be sent from external parties (remember all the warnings on the popular shopping sites to click the 'Order Now' button only once?). To avoid duplicate shipments and unhappy customers, we need to eliminate duplicate messages before subsequent order processing steps are initiated. To meet these requirements, we need to transform a stream of possibly duplicated, encrypted messages containing extra authentication data into a stream of unique, simple plain-text order messages without the extraneous data fields.

![pipe filter](http://www.enterpriseintegrationpatterns.com/img/PipesAndFilters.gif)

CODE

Clone this wiki locally