<?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: Farouk BENNACEUR</title>
    <description>The latest articles on DEV Community by Farouk BENNACEUR (@farben95).</description>
    <link>https://dev.to/farben95</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%2F3044097%2F23fc2957-b84c-450e-8f46-694951877716.png</url>
      <title>DEV Community: Farouk BENNACEUR</title>
      <link>https://dev.to/farben95</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/farben95"/>
    <language>en</language>
    <item>
      <title>Docker Persistence: When and How to Keep Your Container Data</title>
      <dc:creator>Farouk BENNACEUR</dc:creator>
      <pubDate>Sat, 09 Aug 2025 16:14:05 +0000</pubDate>
      <link>https://dev.to/farben95/docker-persistence-when-and-how-to-keep-your-container-data-1b2l</link>
      <guid>https://dev.to/farben95/docker-persistence-when-and-how-to-keep-your-container-data-1b2l</guid>
      <description>&lt;p&gt;Containers are designed to be lightweight, fast, and ephemeral by nature. But what happens when your app needs to retain data between restarts or share files with other containers? That’s where &lt;strong&gt;Docker persistence&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A container is considered &lt;strong&gt;disposed&lt;/strong&gt; (or removed) when it is explicitly deleted with &lt;code&gt;docker rm&lt;/code&gt;, or when it's started with the &lt;code&gt;--rm&lt;/code&gt; flag and stops running. In both cases, any data written inside the container that is not stored in a volume will be lost.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔢 When Should You Persist Container Data?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✅ Persist Data When:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Your application generates data that must survive container restarts (e.g., database data).&lt;/li&gt;
&lt;li&gt;You want to share data between containers.&lt;/li&gt;
&lt;li&gt;You need to back up or migrate container data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Do &lt;em&gt;Not&lt;/em&gt; Persist When:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The container is stateless (e.g., an API service, a compute worker).&lt;/li&gt;
&lt;li&gt;You need temporary cache or test data.&lt;/li&gt;
&lt;li&gt;You want to ensure full isolation and reproducibility.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Persisting unnecessarily can lead to data bloat, complexity, and coupling between host and container.&lt;/p&gt;




&lt;h2&gt;
  
  
  📁 Docker Volume Types and Use Cases
&lt;/h2&gt;

&lt;p&gt;Docker provides several ways to manage persistent data. Here are the main volume types:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Named Volumes&lt;/strong&gt; (Managed Volumes)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Created by Docker&lt;/strong&gt; and stored in its internal directory (e.g., &lt;code&gt;/var/lib/docker/volumes&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Portable and easy to back up.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use When:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want durable data without caring about host path details.&lt;/li&gt;
&lt;li&gt;Running databases, persistent app data.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume create my_data
docker run &lt;span class="nt"&gt;-v&lt;/span&gt; my_data:/app/data my_image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. &lt;strong&gt;Bind Mounts&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Mount a &lt;strong&gt;specific path on the host&lt;/strong&gt; into the container.&lt;/li&gt;
&lt;li&gt;Allows real-time access to host files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use When:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to edit files from your host (e.g., during development).&lt;/li&gt;
&lt;li&gt;Config files need to be versioned on the host.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-v&lt;/span&gt; /path/to/config:/app/config my_image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. &lt;strong&gt;tmpfs Mounts&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stored in RAM&lt;/strong&gt;, lost when the container stops.&lt;/li&gt;
&lt;li&gt;No disk I/O, high-speed access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use When:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need fast access to sensitive or temporary data like passwords.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--tmpfs&lt;/span&gt; /run/cache:rw my_image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ✅ Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Not every container needs persistent storage. But when it does, Docker gives you flexible, powerful tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;named volumes&lt;/strong&gt; for standard persistent data.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;bind mounts&lt;/strong&gt; for full control and local development.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;tmpfs&lt;/strong&gt; when speed or security is a priority.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Manage them wisely, and your containers will be both clean and capable.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>dataengineering</category>
      <category>ai</category>
      <category>containers</category>
    </item>
    <item>
      <title>SQL Execution Order: What Really Happens Under the Hood</title>
      <dc:creator>Farouk BENNACEUR</dc:creator>
      <pubDate>Sat, 12 Apr 2025 22:13:24 +0000</pubDate>
      <link>https://dev.to/farben95/sql-execution-order-what-really-happens-under-the-hood-12ko</link>
      <guid>https://dev.to/farben95/sql-execution-order-what-really-happens-under-the-hood-12ko</guid>
      <description>&lt;p&gt;If you’ve ever written SQL queries and wondered why sometimes things don’t behave as you expect —or why certain clauses must come before others— you’re not alone. SQL can feel a bit weird at first because the way we write queries isn't the way SQL executes them. Let’s unpack this.&lt;/p&gt;

&lt;h2&gt;
  
  
  syntactical Order vs Execution Order
&lt;/h2&gt;

&lt;p&gt;When we write SQL, we often write it in this order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column1, column2
FROM table
JOIN another_table ON ...
WHERE condition
GROUP BY column1
HAVING condition
ORDER BY column2
LIMIT n
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the syntactical order. But it’s not the order in which the database actually processes the query.&lt;/p&gt;

&lt;p&gt;Here’s the execution order in which SQL evaluates a query:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;FROM and JOIN&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;WHERE&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GROUP BY&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HAVING&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SELECT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DISTINCT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ORDER BY&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;LIMIT / OFFSET&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each step builds on the result of the previous. So for example, &lt;strong&gt;&lt;code&gt;WHERE&lt;/code&gt;&lt;/strong&gt; can only filter rows that exist after the &lt;strong&gt;&lt;code&gt;FROM&lt;/code&gt;&lt;/strong&gt; clause has brought them in, but before any grouping or aggregating happens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Execution Order Matters?
&lt;/h2&gt;

&lt;p&gt;Let’s look at a few examples that highlight why this execution order is critical.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 1: Alias Not Recognized in &lt;strong&gt;&lt;code&gt;WHERE&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT salary * 1.1 AS increased_salary
FROM employees
WHERE increased_salary &amp;gt; 50000;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❌ This will throw an error!&lt;br&gt;
Why? Because &lt;strong&gt;&lt;code&gt;WHERE&lt;/code&gt;&lt;/strong&gt; is evaluated before &lt;strong&gt;&lt;code&gt;SELECT&lt;/code&gt;&lt;/strong&gt;. So the alias &lt;code&gt;increased_salary&lt;/code&gt; doesn't exist yet when WHERE runs.&lt;/p&gt;

&lt;p&gt;✅ Fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT salary * 1.1 AS increased_salary
FROM employees
WHERE salary * 1.1 &amp;gt; 50000;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, use a subquery or CTE if you really want to reuse the alias:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WITH temp AS (
  SELECT salary * 1.1 AS increased_salary
  FROM employees
)
SELECT *
FROM temp
WHERE increased_salary &amp;gt; 50000;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example 2: &lt;strong&gt;&lt;code&gt;HAVING&lt;/code&gt;&lt;/strong&gt; Before &lt;strong&gt;&lt;code&gt;SELECT&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT department, COUNT(*) AS total
FROM employees
GROUP BY department;
HAVING total &amp;gt; 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❌ Again, this doesn’t work! The &lt;code&gt;total&lt;/code&gt; alias doesn't exist at the time the &lt;strong&gt;&lt;code&gt;HAVING&lt;/code&gt;&lt;/strong&gt; clause is executed.&lt;/p&gt;

&lt;p&gt;✅ Instead, we need to re-write the aggregation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT department, COUNT(*) AS total
FROM employees
GROUP BY department
HAVING COUNT(*) &amp;gt; 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In practice, some modern DBMS (like MySQL and PostgreSQL) allow you to reference aliases from the SELECT clause inside the HAVING clause as a convenience, even though it's not part of the strict syntactical order.&lt;br&gt;
So the above example will work in many databases. However, this is not guaranteed by the SQL standard and not supported by all DBMS (e.g., SQL Server might not allow it). So it’s better to be cautious.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Best Practices Based on Execution Order
&lt;/h2&gt;

&lt;p&gt;To avoid common SQL pitfalls, keep these tips in mind:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Don’t reuse &lt;code&gt;SELECT&lt;/code&gt; aliases in &lt;code&gt;WHERE&lt;/code&gt; or &lt;code&gt;GROUP BY&lt;/code&gt;.&lt;/strong&gt;&lt;br&gt;
Use the full expression or refactor using a subquery or CTE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Use CTEs (&lt;code&gt;WITH&lt;/code&gt; clauses) for readability and reuse.&lt;/strong&gt;&lt;br&gt;
They're evaluated like subqueries and can help avoid aliasing issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Remember, &lt;code&gt;WHERE&lt;/code&gt; filters rows before aggregation.&lt;/strong&gt;&lt;br&gt;
Use &lt;code&gt;HAVING&lt;/code&gt; to filter after aggregation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Use aliases safely in &lt;code&gt;ORDER BY&lt;/code&gt; (always) and &lt;code&gt;HAVING&lt;/code&gt; (with caution).&lt;/strong&gt;&lt;br&gt;
While many DBMS allow alias use in &lt;code&gt;HAVING&lt;/code&gt;, it’s not standard-compliant. For portability and clarity, prefer reusing the expression or using a subquery/CTE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Think like the engine.&lt;/strong&gt;&lt;br&gt;
Understanding the execution order helps debug tricky issues and write cleaner, more efficient queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;SQL might look like it reads top to bottom — but under the hood, it’s a well-orchestrated sequence of operations. Understanding the processing order helps you write smarter queries, avoid confusing errors, and better leverage the power of SQL.&lt;/p&gt;




&lt;p&gt;What other SQL mysteries have tripped you up? Let’s chat in the comments 👇&lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>datascience</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
