DEV Community

LUCIANO DE CASTRO MARTINS
LUCIANO DE CASTRO MARTINS

Posted on

Design Patterns - Pipeline

Pipeline design pattern comes in handy when we need to execute sequences of steps over an input (request), were each step must be handled by differente software logic.

For instance, imagine a sequence of steps needed to approve a credit, a sequence of tests scores checking before decide if an student go up a year, medical exams results, etc...

Let's dive into a simple credit approval imaginary flow using typescript. You can define your own logic but for the sake of simplicity i'll keep it simple.

For this we'll need the following domain:
a card issuer represented by the enum CardIssuer, a person (Person Interface) and a Credit domain class (credit interface), see bellow:

Image description

So with the basic model created let's define our Pipeline implementation, but before that i'll need a CreditCardEvaluation class simply to wrap our domain so handling all related information becomes easier.

Image description

Finally an interface that defines our handlers contract (the contract to handle a request), and the pipeline class.

Image description

Now we must define what we want to validate/check. For that i defined a basic credit validator (BasicCreditProcessor), a guarantee validator and a credit card message processor, classes are as follow:

Image description

Now that we have our structure, let's test it:

Image description

and the result is:

Image description

a second test:

Image description

with the result:

Image description

by using the pipeline design pattern we avoid having a single class with multiple responsabilities and adding more processors "step/executors" are as easy as writing them and placing them inside the pipeline. that is it.

Neon image

Serverless Postgres in 300ms (❗️)

10 free databases with autoscaling, scale-to-zero, and read replicas. Start building without infrastructure headaches. No credit card needed.

Try for Free →

Top comments (0)

ACI image

ACI.dev: The Only MCP Server Your AI Agents Need

ACI.dev’s open-source tool-use platform and Unified MCP Server turns 600+ functions into two simple MCP tools on one server—search and execute. Comes with multi-tenant auth and natural-language permission scopes. 100% open-source under Apache 2.0.

Star our GitHub!

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay