Essay

The Art of Reading Production Code

Start with one request, not the file tree. A reading path for engineers who just inherited a codebase and need to be useful this week.

Swati S.11 min read

TL;DR: Start with a request, not files: trace one complete flow from edge to database. Build a spatial map of boundaries and cross-cutting concerns, read tests for intent, and use logs and commit history to learn why the code looks the way it does. One flow teaches more than a hundred files.

A five-step reading path: entry point, follow one request, tests and logs, history and blame, ask the owner, with a loop back to tracing again if it is still unclear
Read a codebase as a path with an order, and loop back to the request when you get lost.

When you're handed a new codebase—maybe it's Monday morning and your manager says "you're taking over the payments service"—don't open your editor. Don't start reading files. Start with a request.

Most engineers do the opposite. They open the folder tree, expand everything, and read from the top. By Wednesday they know a lot of file names and still can't say what happens when a customer pays. This essay is for the engineer in that spot, and it gives you a reading order you can use this week.

Find where requests enter. Trace one complete flow from the edge to the database. One flow. One request. Follow it all the way through.

# Start here: What path does /api/users/{id} take?
@app.route("/api/users/<user_id>")
def get_user(user_id):
    return user_service.fetch(user_id)

# Then follow: user_service → database → response

You're not learning the code. You're learning the system's behavior under request. Functions are implementation details. Flows are architecture.

When I first joined a team working on a large e-commerce platform, I made the mistake of trying to understand the codebase by reading files alphabetically. Two weeks later, I understood files, not the system. When a bug appeared, I had no idea where to look.

The engineer who mentored me said: "Pick a user action. A real one. Click 'add to cart.' Trace that click all the way through. Where does it hit first? What service does it call? What database does it write to? What cache gets invalidated?"

That one flow taught me more about the system than reading a hundred files.

A scene to hold on to

Picture a support ticket: "Customer was charged twice for one order." You have never seen this service. You have the order ID and a log search box.

A reader of files starts guessing which folder holds "payments". A reader of flows searches the logs for the order ID, finds a line like payment.authorize order=8841 attempt=2, and greps the repo for payment.authorize. That lands on the exact function. A line above it says attempt=, so there is a retry. Two minutes in, you have a theory to test: the retry did not check whether attempt one had already worked.

You did not need to understand the whole service. You needed one thread and the habit of pulling it. That habit is the rest of this essay.

The reading path

Here is the order I'd give a new teammate. Each step gets its own section below, and the picture at the top shows how they connect.

  1. Entry point. Find the route, consumer, or cron job that starts your chosen flow.
  2. Follow one request. Walk it to the data store and back, noting each boundary you cross.
  3. Tests and logs. Read what the authors promised and what the running system says.
  4. History and blame. Find out why the odd parts are odd.
  5. Ask the owner. Bring a specific question and your own guess.

If a step leaves you confused, go back to step 2 with a narrower request. Don't widen the scope.

Build maps, not dictionaries

Don't try to memorize every function. You'll forget. Instead, build a spatial map—a mental model of the landscape.

Ask yourself:

  • What are the major boundaries? (API layer, service layer, data layer)
  • Where do cross-cutting concerns live? (auth, logging, caching, rate limiting)
  • Which modules communicate with which? (dependency graph, not call stack)

I once worked with a codebase where authentication logic was scattered across twelve different files. I couldn't remember all twelve, but I knew they all lived in a middleware/ directory, and they all implemented the same interface. The geography helped me navigate faster than memorization ever could.

Sketch the map. Label the regions. You'll forget function names, but the geography stays. When a bug appears in the "authentication region," you know where to look, even if you don't remember the exact function name.

A good first map fits on one page. Draw three or four boxes, draw arrows for who calls whom, and mark where authentication and caching sit. If the code follows separation of concerns, the boxes will match the folders. If they don't, that mismatch is the first thing worth writing down.

Read tests to understand intent

Tests document expected behavior, not implementation. They're specifications in disguise.

When a test says "should handle concurrent requests," that's a design constraint. When it mocks three services, those are dependencies. When it expects a specific error message, that's a contract with the caller.

I once spent hours trying to understand why a function had such complex logic. Then I read the tests. The tests revealed the function needed to handle five edge cases I hadn't considered. The complexity wasn't overengineering—it was necessity.

Read tests first. They tell you what the code is supposed to do, not how it does it. That "what" is what you need to understand before you dive into the "how."

Read the logs next

Tests show what the authors expected. Logs show what actually happens. Run the flow you chose, or find a recent sample in your log tool, and read every line it produced in order.

Then do one small exercise. Take a single log line and find the code that wrote it. You'll cross two or three layers doing that, and each hop adds to your map. Good error handling and logging leaves breadcrumbs like request IDs and attempt counts. If the flow logs nothing, that is a finding too, and it tells you where you'll be blind in your first incident. Monitoring and observability explains what to add.

Ask why before how

Before asking "How does this work?", ask "Why does this exist?" Understanding purpose clarifies implementation.

A function that seems overcomplicated might be solving a problem you haven't seen yet. That abstraction that looks unnecessary might have been added after three similar bugs. That caching layer that seems premature might have been added after a production incident.

I remember questioning why a service had such elaborate retry logic. It seemed like overengineering. Then I read the postmortem. The service had failed during a network partition, causing a cascade of failures. The retry logic was added to handle exactly that scenario.

Read code like you're debugging a bug you haven't found. Question assumptions. Trace edge cases. The codebase is trying to tell you something about the problem it solves, not just how it solves it.

A useful rule: before you propose deleting anything odd, write down one possible reason it exists. If you can't think of any, find the commit. This is Chesterton's fence applied to code. Retry loops, timeouts, and strange ordering of calls are the usual places where an old outage is buried. For a taste of what those stories look like, read the race condition bug postmortem and notice how small the eventual fix is compared to the confusion before it.

Annotate as you learn

Don't read passively. Take notes. Use comments (or a separate file) to capture:

  • What surprised you?
  • What patterns repeat?
  • Where do assumptions break?
  • What decisions seem arbitrary?

Your annotations become documentation for your future self. They also reveal gaps in your understanding. If you can't explain it simply, you don't understand it yet.

I keep a learning log for every new codebase. It starts as questions. "Why does this use Redis here?" becomes "Redis is used for session storage because sessions need to be shared across multiple servers." The process of explaining it to myself solidifies the understanding.

Keep the log in a plain file next to your work, not in a wiki nobody opens. One line per question, one line per answer, and a date. After two weeks you'll have a real onboarding page for the next person, and you'll have written it with the fresh eyes that long-time owners lost years ago. That is also the best argument for sending your first pull request as a doc fix.

Follow the data

Data flow is easier to follow than code flow. Start with: "Where does the data come from?" Then: "Where does it go?" Finally: "How does it get transformed along the way?"

In a microservices architecture, a user request might touch six services. Don't try to understand all six at once. Follow the data. Where does the user ID come from? Where does it get validated? Where does it get enriched? Where does it get persisted?

Following data helped me understand a complex payment processing system. I started with a payment intent. I followed it through validation, fraud checks, processor communication, and confirmation. That one data flow gave me a complete picture of how payments worked.

When the flow crosses a message queue, the trail goes cold in the code, because the producer and consumer live in different places. Search for the topic or queue name instead. That string is the link between the two halves, and it's usually unique enough to grep.

Read commit messages

Commit messages are historical documentation. They tell you why code was added, what bug it fixed, what feature it enabled.

A commit message that says "Fix race condition in cache invalidation" tells you more than the code does. It tells you there was a race condition. It tells you cache invalidation was the problem. It tells you this code exists to prevent a specific bug.

I once found a complex locking mechanism that seemed unnecessary. The commit message said: "Fix deadlock in concurrent order processing." The code made sense once I understood the problem it was solving.

The workflow takes about a minute. Run git blame on the confusing lines, copy the commit hash, and run git show on it. Read the message, then the diff around it. If the message links a ticket or pull request, open that too, because the review thread often has the real explanation. If every message says "fix" or "updates", you've learned something about the team's habits, and you'll lean on tests and logs more.

Learn the idioms

Every codebase has idioms—patterns that repeat. Learn them.

One codebase might use dependency injection everywhere. Another might use factory functions. One might favor composition. Another might use inheritance. These idioms aren't just style—they're architectural decisions.

Learning idioms helps you read faster. When you see a factory function, you know what pattern you're looking at. You don't need to understand the implementation—you understand the idiom.

If a name like factory or strategy shows up, you can read the shape instead of the details. A quick way to spot idioms: open three files in the same folder and look at what they share. Same constructor shape, same error type, same logging call. Whatever repeats is the house style, and new code should match it.

Practice on unfamiliar code

The best way to get better at reading code is to read code you've never seen. Find an open-source project. Pick a feature. Read the code that implements it. Don't just read it—understand it. Then read the tests. Then read the documentation. Then read the discussions.

Do this regularly. Read code in languages you don't know. Read code in domains you don't understand. The skill transfers. The more code you read, the faster you read.

The best engineers read code like scientists read papers—critically, with purpose, building on what they learn. They don't try to memorize everything. They build maps. They ask why. They annotate. They follow data. They learn idioms.

Start narrow. Go deep. Then branch out. The codebase is trying to tell you something. Listen carefully.

Reading and debugging are the same muscle. If you want the next step, On Cultivating Debugging Sense and Building Debugging Intuition cover what to do once you have found the broken part. And when you review someone else's change in a codebase you now understand, Code Review as Teaching is the other half of the loop.

Try this week

Pick one flow in the codebase you work in, ideally the one that wakes people up at night. Then do five things, in order:

  1. Write the entry point on a sticky note: route, file, line.
  2. Trace the request to the data store and list each boundary it crosses.
  3. Find one log line from that flow and match it to the code that wrote it.
  4. Run git blame on the one line that confuses you most and read the commit.
  5. Post your five-line summary to the team and ask the owner what you got wrong.

It will take about two hours. Then do it again next week with a different flow. The third one is when you start getting fast.

Frequently asked questions

How do I understand a large codebase quickly?
Don't start by reading files. Find where requests enter and trace one complete flow from edge to database. One flow teaches more than a hundred files. You're learning the system's behavior; functions are details, flows are architecture.
Should I memorize every function?
No. Build a spatial map: major boundaries (API, service, data layer), cross-cutting concerns (auth, logging, caching), which modules talk to whom. Geography beats memorization. Read tests first—they document expected behavior before you dive into implementation.
How do I avoid getting lost in a new codebase?
Ask 'Why does this exist?' before 'How does it work?' Purpose clarifies implementation. Take notes: capture assumptions, edge cases, open questions. Don't read passively. Pick a real user action and trace it all the way through.
What do I do when the code has no tests and no docs?
Use the running system as your spec. Hit one endpoint, read the log lines it produces, and match each line to the code that wrote it. Then add one small test around the flow you traced. You get a safety net and a record of what you learned. The same habit works for error handling and logging questions: logs tell you what the authors thought was worth saying.
When is it fine to ask a teammate instead of reading more?
After you have a specific question and a guess. "I traced checkout to reserve_stock and I think the retry is there because of duplicate charges. Is that right?" takes a minute to answer and shows the work you did. "How does checkout work?" costs the other person half an hour.
How does git history help me read code?
git blame tells you which commit last touched a line, and the commit message or linked ticket often explains the bug behind it. A strange retry or lock usually has a story. The same instinct that makes you read a postmortem like the deadlock in payment processing applies to your own repo.
Can I use AI to explain unfamiliar code?
Yes, as a second opinion after you traced the flow yourself. An AI summary can sound confident and still miss why a retry exists. Use it to name patterns and suggest where to look next, then confirm in the code and the logs. How to Actually Learn From AI-Generated Code covers that habit in more depth.
How do I practice reading code when I'm not on a new team?
Pick an open-source project you already use and trace one feature, such as how a library retries a failed request. Write down the path in five lines. You can also open a design you know from the practice problems and ask where its edge, service, and data boundaries would sit in a real repo.

About the author

Swati S. helps you master system design with patience. We believe in curiosity-led engineering, reflective writing, and designing systems that make future changes feel calm.

Ask about this page

No signup needed · Sign in to save your plan