What's the mindset shift we need to stop being data script monkeys and start thinking code as moving parts that make sense.
By Alejandro Aboy
Published: 2025-09-06
URL: https://thepipeandtheline.substack.com/p/stop-writing-pipelines-design-code
Hi there! Alejandro here 😊
Suscribe if you like to read about technical data & AI learnings, deep dives!
Enjoy the reading and let me know in the comments what you think about it 👨🏻💻
Learning to code is not a big issue: you can struggle with complex coding structured and eventually understanding after trial/error + experience.
Personal Experience 😂
I remember one time at another job when I built a script to fetch data from PageSpeed Insights to track Core Web Vitals.
One “quick fix” leads to another. Before you know it, you have an all-in-one monster that’s impossible to debug, test, or extend.
Multiple functions rely on each other, with some doing five things in one run a complete Frankenstein.
It reminded me of that Scooby Doo meme you’ve probably seen a couple of times:
The “Just A Script” Mindset 😅
Most data people I meet (past me included 🙋🏻♂️) treat pipelines like long scripts:
-
Read a file
-
Transform the data
-
Load it somewhere
-
Add a few if-else fixes
-
Ship it
Frustration as a beginner comes from not understanding how to understand how to go from idea to code, but frustration as a senior engineer comes from not knowing how to maintain code or how to approach it properly beyond the principle of "it works or it doesn't".
When you start your career whether through a course, bootcamp, or self taught in the wild, you learn isolated tricks. Over time, these tricks eventually compund into comprehensive skills that get you where you want to go.
At some point, you feel confident enough to create data pipelines or programs that make sense, get the job done, and call it a day.
But you keep doing just that: writing "pipelines" and "scripts" without planning or designing how the pieces fit together based on solid fundamentals like Functional Programming.
Mindset shift to start making things the right way 🎯
Move away from the “pipeline” or "script" mindset and start thinking of your code as a puzzle that fits together logically.
Don't do it for elegance. Do it for your future self six months from now, who has to read and understand that code quickly to fix a particular issue.
We will cover some concepts from Erik Normand's book Grokking Simplicity. These principles mostly come from Software Engineering, but we can apply many of them to Data coding patterns in Python.
How do we connect Functional Programming to Data Engineering? As always, there’s a way.
Image generated with ChatGPT.
Thanks for reading The Pipe & The Line! Subscribe for free to receive new posts and support my work.
📐 Actions, Calculations, and Data
These concepts form the skeleton for designing robust code. They help you avoid situations like my personal experience by encouraging you to categorize pieces and separate concerns properly.
Eric Normand’s Grokking Simplicity introduces a simple but powerful framework:
-
Actions → Code that interacts with the outside world (I/O, APIs, databases) and can’t be replayed without changing something in the real world.
-
e.g. Writing a new row to a database table or sending an HTTP request to an external API.
-
Calculations → Pure functions that return the same output for the same input, without side effects.
-
e.g. A function that calculates the average session duration from a list of session times.
-
Data → Immutable structures passed around without being changed in place. It can operate independently, acts as the glue between parts, and is easy to inspect.
-
e.g. A dataframe passed between an action and a calculation for further processing.
Separating these three makes your code predictable, testable, and easy to change.
Note that the world out there is unpredictable in so many ways. Users might find 7 seven ways of writing a Country name and it might break apart these concepts in theory. So use them wisely and be flexible about it.
Although these principles mainly belong to Software Engineering, there's a lot we can take from them into Data coding patterns in Python.
Now, let's go through the tactical fundamentals behind good code design.
Thanks for reading The Pipe & The Line! This post is public so feel free to share it.
🎯 Single Responsibility: One Function, One Job
A function that does five things instead of five small, clear functions can cause many problems.
There’s a saying: "If you describe what a function does and have to say “and,” “or,” or “but,” it probably has more than one responsibility."
For data engineering, this means:
-
Extract functions should only extract. Connect to that API and get that JSON, that's it.
-
Transform functions should only transform. Take that JSON output and make it a DataFrame. Leave the cleanup for another function.
-
Load functions should only load. Take that DataFrame and save it into Snowflake accordingly, no other step involved.
As long as you follow this principle, you are more likely to make clean, maintainable, and readable code.
By the end of this process, if you read function names like "extractapi," "transformjson," "loaddfto_snowflake" and don't have to explain anything, you are on track!
Think of it as labels in boxes. If you just read it without opening it, do you know what the box contains? If the answer is no, the box might contain multiple things that have nothing to do with each other, make it confusing to unpack after moving to another home.
You can check out this article on how to add maintainability and complexity code checks to your CI/CD in GitHub here:
🔍 Decoupling: Pulling Things Apart
This is the art of making everything work in isolation.
Earlier, we talked about the single responsibility principle, which is the backbone of decoupling.
If two functions are tightly connected and one relies on the other's output, a failure in one can trigger a chain reaction causing the other to fail too.
In Data Engineering, we face this often.
Particularly in ETL processes, we rely on the output of one function as the input for another.
That's not wrong per se, but we need to break it down in ways that are easy to track if there's any trouble.
Earlier, we talked about a function to extract from an API, another function to convert to DataFrame, and another...
For example:
import pandas as pd
def etl_pipeline(file_path, conn):
df = pd.read_csv(file_path) # extract
df = df[df["amount"] > 0] # transform
df.to_sql("transactions", conn, if_exists="replace", index=False) # load
A failure here will likely output:
Traceback (most recent call last):
File "pipeline.py", line 3, in <module> etl_pipeline("data.csv", conn) File "pipeline.py", line 6, in etl_pipeline df = df[df["amount"] > 0] KeyError: 'amount'
But a failure here will provide better context:
import pandas as pd
def extract(file_path):
return pd.read_csv(file_path)
def transform(df):
return df[df["amount"] > 0]
def etl_pipeline():
data = extract("data.csv") # isolated extraction
cleaned = transform(data) # isolated transformation
return cleaned
The error output:
Traceback (most recent call last):
File "pipeline.py", line 10, in <module> cleaned = transform(data)
File "pipeline.py", line 7, in transform return df[df["amount"] > 0] File ".../pandas/core/frame.py", line 4102, in __getitem__ indexer = self.columns.get_loc(key)
KeyError: 'amount'
Despite being a simple example, when you have production codebases on Airflow and need to trace an issue, this approach saves you days.
You can add Radon and Xenon to python project to help your team fight these monsters:
🧱 Stratified Design: Layers of Abstraction
Grokking Simplicity talks about keeping your code in layers, for example:
-
Business Layer – Least stable, changes often (KPIs, custom rules). For example, calculating monthly active users or churn rate based on transformed data.
-
Domain Layer – Core transformations and calculations, such as functions that normalize data formats or aggregate metrics.
-
Tech Stack Layer – Most stable (API extractions, database connectors).
You should also follow previous concepts: a function in one layer shouldn’t mix responsibilities from another. For example, your “calculate churn rate” logic should never directly open a database connection.
These principles work really well alongside data modeling concepts such as "data marts" since all logic from a specific domain is grouped together, which ends up working as natural documentation. So, if you don't document because there's always something better to do, you might be ok since the code is already "speaking".
That said, always think of the context. If you are working on small projects this might be a huge overkill. Just decoupling and one responsibility principles might get the code clean already without getting too fancy.
⚡ Data Engineering Code Design
The goal is to stop gluing steps together.
When we translate this into ETL/ELT workflows, the objective is decoupling:
-
Actions at the boundaries: reading from S3 and writing to a DB are actions that interact with the outside world. They need a clear, isolated context to avoid chain reactions.
-
Calculations in the middle: transformations, validations, and enrichments are predictable and should run when it’s safe.
-
Data as the glue: keep data passed between steps as something you can inspect and check for progress. If, after running calculations like transformations, the expected columns are missing, you’ll notice this by treating the dataframe as the "Data" type that Grokking Simplicity describes.
💡 Example: Applying These Principles to ETL
Typical “pipeline” script. Everything’s coupled together: extraction, transformation, and loading all in one place. Testing just the transform step? Painful:
import pandas as pd
import psycopg2
df = pd.read_csv("data.csv")
df = df[df["status"] == "active"]
df["normalized_amount"] = df["amount"] / df["amount"].max()
conn = psycopg2.connect("...")
df.to_sql("clean_data", conn, if_exists="replace", index=False)
Designed with Actions / Calculations / Data + Single Responsibility:
import pandas as pd
# Action: Extract
def extract_csv(path):
return pd.read_csv(path)
# Calculation: Transform
def normalize_and_filter(df):
df = df[df["status"] == "active"].copy()
df["normalized_amount"] = df["amount"] / df["amount"].max()
return df
# Action: Load
def load_to_postgres(df, conn):
df.to_sql("clean_data", conn, if_exists="replace", index=False)
# Orchestration
def etl(filepath, conn):
raw = extract_csv(filepath)
cleaned = normalize_and_filter(raw)
load_to_postgres(cleaned, conn)
🔍 The Takeaway
Isolate actions from calculations so you can run and rerun calculations without side effects.
Combined with decoupling and single responsibility, you get painless debugging, simple testing, and natural flows.
Think of your code in blocks that fit together instead of just code, and everything will look different.
If there’s something you want to mention about this type of content? I would like to here more about it to improve the quality of upcoming posts!
📝 TL;DR
-
Learning to code often means writing isolated scripts that work but become hard to maintain. Shifting your mindset to design code as a well structured puzzle helps future you avoid headaches.
-
Separating code into Actions (I/O), Calculations (pure functions), and Data (immutable structures) makes your code predictable and testable.
-
Single Responsibility Principle means each function should do one clear job: extract, transform, or load to keep code clean and maintainable.
-
Decoupling means breaking your code so each part works independently, making debugging and tracing errors much easier.
-
Stratified Design organizes code into layers (Business, Domain, Tech Stack) to separate concerns and improve clarity and stability.
-
In Data Engineering, avoid gluing steps together; isolate actions at boundaries, keep calculations pure in the middle, and treat data as the glue that connects everything.
-
Applying these principles in ETL scripts leads to cleaner, testable, and scalable workflows that are easier to debug and maintain.
If you enjoyed the content, hit the like ❤️ button, share, comment, repost, and all those nice things people do when like stuff these days. Glad to know you made it to this part!

Hi, I am Alejandro Aboy. I am currently working as a Data Engineer. I started in digital marketing at 19. I gained experience in website tracking, advertising, and analytics. I also founded my agency. In 2021, I found my passion for data engineering. So, I shifted my career focus, despite lacking a CS degree. I'm now pursuing this path, leveraging my diverse experience and willingness to learn.
