<?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: Ammar Eyad</title>
    <description>The latest articles on DEV Community by Ammar Eyad (@ammar_eyad).</description>
    <link>https://dev.to/ammar_eyad</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4112066%2F70b82f05-3ad6-4e77-a574-75f1d0ddd6ae.png</url>
      <title>DEV Community: Ammar Eyad</title>
      <link>https://dev.to/ammar_eyad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ammar_eyad"/>
    <language>en</language>
    <item>
      <title>Why You Shouldn’t Store Large Files in Your Database: Database vs. Amazon S3</title>
      <dc:creator>Ammar Eyad</dc:creator>
      <pubDate>Mon, 07 Sep 2026 05:05:15 +0000</pubDate>
      <link>https://dev.to/ammar_eyad/why-you-shouldnt-store-large-files-in-your-database-database-vs-amazon-s3-hec</link>
      <guid>https://dev.to/ammar_eyad/why-you-shouldnt-store-large-files-in-your-database-database-vs-amazon-s3-hec</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Storing files in a database instead of S3 introduces two massive architectural bottlenecks as your application scales:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  1. CDN becomes much harder to use
&lt;/h3&gt;

&lt;p&gt;One of the biggest advantages of S3 is how easily it works with a CDN such as Amazon CloudFront or Cloudflare.&lt;/p&gt;

&lt;p&gt;Imagine you have millions of users requesting the same images.&lt;/p&gt;

&lt;p&gt;With S3 and a CDN, the CDN can cache those images at locations around the world. Users can get the file from a nearby edge location instead of requesting it from your application every time.&lt;/p&gt;

&lt;p&gt;This is exactly what we want for things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Images&lt;/li&gt;
&lt;li&gt;Videos&lt;/li&gt;
&lt;li&gt;PDFs&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;Other static content&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now imagine the image is stored as a BLOB inside your database.&lt;/p&gt;

&lt;p&gt;If your images are locked in a database, your &lt;strong&gt;CDN&lt;/strong&gt; is effectively blind to them. Every single image request must hit your web server, which must then execute a heavy database query to fetch the binary data, stream it back to the web server, and then serve it to the client. You are forcing your most expensive piece of infrastructure (the database) to act as a dumb file server, completely bypassing the speed and cost benefits of edge caching.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Database replication becomes heavier
&lt;/h2&gt;

&lt;p&gt;Production databases usually have replicas for &lt;strong&gt;high availability&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If your database contains mostly structured data, replication is relatively straightforward.&lt;/p&gt;

&lt;p&gt;But imagine your database contains hundreds of gigabytes or even terabytes of images and videos.&lt;/p&gt;

&lt;p&gt;Now those large binary objects also become part of your database replication and backup workload.&lt;/p&gt;

&lt;p&gt;For example, instead of replicating:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users
Orders
Products
Payments
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you might also be replicating:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;500 GB of images
1 TB of videos
200 GB of documents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That can make replication, backups, and restores significantly heavier.&lt;/p&gt;

&lt;p&gt;The same applies when you need to restore your database.&lt;/p&gt;

&lt;p&gt;A database backup containing huge amounts of binary data can take much longer to restore than a database containing only structured application data.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Your database becomes unnecessarily large
&lt;/h2&gt;

&lt;p&gt;Databases are extremely good at what they are designed for.&lt;/p&gt;

&lt;p&gt;They are great for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Relationships&lt;/li&gt;
&lt;li&gt;Transactions&lt;/li&gt;
&lt;li&gt;Queries&lt;/li&gt;
&lt;li&gt;Indexes&lt;/li&gt;
&lt;li&gt;Structured data&lt;/li&gt;
&lt;li&gt;Consistency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But storing large files is a different problem.&lt;/p&gt;

&lt;p&gt;Object storage is designed specifically for storing large objects.&lt;/p&gt;

&lt;p&gt;So instead of making the database responsible for everything, we can separate the responsibilities.&lt;/p&gt;

&lt;p&gt;The database stores:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
Order
Payment
File metadata
File reference
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;S3 stores:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Images
Videos
PDFs
Documents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each system does what it is good at.&lt;/p&gt;

&lt;h2&gt;
  
  
  What about the physical storage behind S3?
&lt;/h2&gt;

&lt;p&gt;Another interesting question is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where does S3 actually store my file?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the end of the day, the data has to live on physical storage hardware.&lt;/p&gt;

&lt;p&gt;But as an S3 user, you don't need to know whether your particular object is sitting on an HDD, SSD, or which physical disk contains it.&lt;/p&gt;

&lt;p&gt;AWS manages that infrastructure for you.&lt;/p&gt;

&lt;p&gt;You interact with S3 as object storage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-bucket/users/123/profile.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't interact with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Disk 123
Sector 456
SSD 789
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That abstraction is one of the main benefits of object storage.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does the typical architecture look like?
&lt;/h2&gt;

&lt;p&gt;A common approach is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    +--- Database
    |      File metadata
    |
    +--- S3
           Actual file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For uploads, we can even use a presigned URL so the client uploads the file directly to S3 instead of sending the entire file through our application server.&lt;/p&gt;

&lt;p&gt;The database then only needs to know things like the file name, size, content type, and S3 key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is storing BLOBs in a database always wrong?
&lt;/h2&gt;

&lt;p&gt;No.&lt;/p&gt;

&lt;p&gt;There are cases where it can be perfectly reasonable.&lt;/p&gt;

&lt;p&gt;For example, if the files are very small and the application is simple, storing them in the database might be easier and completely acceptable.&lt;/p&gt;

&lt;p&gt;The important thing is to understand the trade-off.&lt;/p&gt;

&lt;p&gt;For a large-scale system, I generally prefer this simple rule:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database for structured data and metadata.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;S3/object storage for large files.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It keeps the architecture cleaner, allows the file storage to scale independently, makes CDN integration easier, and avoids turning your primary database into a file server.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>database</category>
    </item>
  </channel>
</rss>
