<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oluwatomi Ayobami</title>
    <description>The latest articles on DEV Community by Oluwatomi Ayobami (@taurean04_14).</description>
    <link>https://dev.to/taurean04_14</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2450657%2Fb6b87c42-eb43-43b0-b5e8-4c0287b65f97.png</url>
      <title>DEV Community: Oluwatomi Ayobami</title>
      <link>https://dev.to/taurean04_14</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/taurean04_14"/>
    <language>en</language>
    <item>
      <title>Dear Developer: Your Database Isn't a File Cabinet!</title>
      <dc:creator>Oluwatomi Ayobami</dc:creator>
      <pubDate>Fri, 21 Nov 2025 18:55:32 +0000</pubDate>
      <link>https://dev.to/taurean04_14/dear-developer-your-database-isnt-a-file-cabinet-39ng</link>
      <guid>https://dev.to/taurean04_14/dear-developer-your-database-isnt-a-file-cabinet-39ng</guid>
      <description>&lt;p&gt;Hey guys! I’m an Engineering Manager, and I’m sharing some notes deep from the &lt;em&gt;development trenches&lt;/em&gt;. I wanted to kick off my writing journey by talking about a massive performance mistake that I see all the time when I do code reviews. It’s about how we treat our &lt;strong&gt;Database&lt;/strong&gt; (or DB for short). In my experience, several issues crop up when databases aren't utilized to their full potential.&lt;/p&gt;

&lt;p&gt;Look, we often treat the DB like a basic File Cabinet. We ask for raw data, it returns a massive file, and then &lt;strong&gt;&lt;em&gt;WE&lt;/em&gt;&lt;/strong&gt; (the application layer) have to do all the complicated work. That's kind of how the front-end treats us!&lt;/p&gt;

&lt;p&gt;But here's the crazy part: your database is actually a super-powerful, specialized machine built for searching, connecting, and crunching data. When you force your application to handle all that work, you trigger what I’ll call &lt;strong&gt;The Processing Tax&lt;/strong&gt;. This is basically pointless latency from all those network trips and wasted CPU cycles.&lt;/p&gt;

&lt;p&gt;Are you ready to stop paying the tax? Well, if that’s a yes, let's check out the two worst performance sins and how to fix them with cleaner SQL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhyxxx7wgo6jcy6chhf9r.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhyxxx7wgo6jcy6chhf9r.jpg" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The Ping-Pong Player: Chained Queries&lt;/strong&gt;&lt;br&gt;
This one happens a lot, especially when folks rely too heavily on their ORMs (Object-Relational Mappers) and forget that every single database call is a costly trip across the network. This often results in a chain reaction of queries, where each call triggers another, and another, and another...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem: Too Many Trips!&lt;/strong&gt;&lt;br&gt;
For example:&lt;/p&gt;

&lt;p&gt;You need data about a user's active beneficiaries. you try to get it and your code often ends up looking like this step-by-step nightmare:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bad Practice: The Chained Call&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❌THE BAD WAY ( with three potential network hops!)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Check if the user exists&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user = db.query_one("SELECT * FROM users WHERE id = :id;")
if user is None:
     return 404
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Check if the user is active&lt;/strong&gt; (could be combined with Step 1, but often isn't)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if user.status != 'active':
     return 403 // Forbidden
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Now, to go get the beneficiaries&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;beneficiaries = db.query_all("SELECT * FROM beneficiaries WHERE user_id = :id;")
      return beneficiaries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything works, you would have just made three separate network calls. Literally, three round-trips for one API request. That repeated back-and-forth is pure latency poison, and it adds up fast...and that’s if it even works!&lt;/p&gt;

&lt;p&gt;For more analogy-oriented learners, it’s almost like asking your assistant to drive to the bank, come back and tell you the weather, and then drive back to the bank to deposit a check. The database lives right there! It can do all the checks in one go. Make sense?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix: One Query, One Result&lt;/strong&gt;&lt;br&gt;
We need to mash all that logic (user exists, user is active, get beneficiaries) into one quick, efficient database command.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Good Practice: A Single, Surgical Query&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✔ THE GOOD WAY (one network hop)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
   b.* FROM
   beneficiaries b
JOIN
   users u ON b.user_id = u.id
WHERE
   u.id = :user_id
   AND u.status = 'active';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: Your database engine, which is already built for speed, handles the whole thing in a single trip. You get back exactly the data you need with no messy application branching required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Data Janitor: Over-Fetching &amp;amp; Post-Processing&lt;/strong&gt;&lt;br&gt;
Our databases aren't just great at storage; they're also amazing at doing math and changing data shape. This happens when we're scared of, or just forget about, using functions like &lt;code&gt;SUM()&lt;/code&gt;, &lt;code&gt;AVG()&lt;/code&gt;, or &lt;code&gt;CONCAT()&lt;/code&gt;. Instead of leveraging the DB's power, we're stuck cleaning up unnecessary data and doing calculations in code, adding extra load and slowing things down.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem: You're Doing the Database's Homework&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;A. The Summing Mistake&lt;/strong&gt;&lt;br&gt;
For example:&lt;/p&gt;

&lt;p&gt;Do you need the total sales volume for the day?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bad Practice: Fetch everything, then loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❌THE BAD WAY (involving fetching 10,000 rows to add them up)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;orders = db.query_all("SELECT amount FROM orders WHERE date = :today;")
total_revenue = 0
for order in orders:
     total_revenue += order.amount
return total_revenue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You just paid the &lt;strong&gt;Processing Tax&lt;/strong&gt; by making your server download and loop through thousands of records.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B. The Transformation Mistake&lt;/strong&gt;&lt;br&gt;
Say you store only the image name (ruth.jpg) in the database, but you need the full URL (&lt;a href="https://cdn.com/ruth.jpg" rel="noopener noreferrer"&gt;https://cdn.com/ruth.jpg&lt;/a&gt;) for the front-end.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bad Practice: Looping to transform&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❌ THE BAD WAY (Transforming data in the application layer)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;users = db.query_all("SELECT name, image_filename FROM users;")
for user in users:
   user.image_url = "[https://cdn.com/](https://cdn.com/)" + user.image_filename
return users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That loop adds unnecessary milliseconds to your API response time, proportional to how many users you have.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix: Let the DB Do the Heavy Lif&lt;/strong&gt;ting&lt;br&gt;
Use the awesome features your database already has. Less data flying over the network means a much faster app.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Good Practice: Use Aggregation (SUM) and Transformation (CONCAT)&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
✔ THE GOOD WAY (Use the Database's Calculator)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Aggregation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT SUM(amount) AS total_revenue FROM orders WHERE date = :today;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For Transformation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
   name,
   CONCAT('[https://cdn.com/](https://cdn.com/)', image_filename) AS image_url
FROM
   users; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
To wrap things up, dear developer, treating your database like a file cabinet can lead to major performance issues. By leveraging your database's capabilities, you can avoid unnecessary network trips and calculations in your application code.&lt;/p&gt;

&lt;p&gt;This means using SQL functions like &lt;code&gt;SUM()&lt;/code&gt;, &lt;code&gt;AVG()&lt;/code&gt;, and &lt;code&gt;CONCAT()&lt;/code&gt; to handle data processing directly in the database. By doing so, you'll reduce latency, improve efficiency, and make your app faster.&lt;/p&gt;

&lt;p&gt;Take it from a genuinely concerned fellow developer, stop paying the Processing Tax and let your database do the heavy lifting!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>database</category>
      <category>sql</category>
      <category>softwareengineering</category>
    </item>
  </channel>
</rss>
