<?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: Akash</title>
    <description>The latest articles on DEV Community by Akash (@akash_a74ce19b1daf04b4891).</description>
    <link>https://dev.to/akash_a74ce19b1daf04b4891</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%2F3435473%2F21d34d07-e599-4cfb-b772-35ffbeaa5220.jpg</url>
      <title>DEV Community: Akash</title>
      <link>https://dev.to/akash_a74ce19b1daf04b4891</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akash_a74ce19b1daf04b4891"/>
    <language>en</language>
    <item>
      <title>SQLAlchemy Architecture — Notes from a Beginner Learning Backend</title>
      <dc:creator>Akash</dc:creator>
      <pubDate>Sat, 17 Jan 2026 07:17:15 +0000</pubDate>
      <link>https://dev.to/akash_a74ce19b1daf04b4891/sqlalchemy-architecture-notes-from-a-beginner-learning-backend-5bdn</link>
      <guid>https://dev.to/akash_a74ce19b1daf04b4891/sqlalchemy-architecture-notes-from-a-beginner-learning-backend-5bdn</guid>
      <description>&lt;p&gt;I am still new to backend development and databases. While trying to understand SQLAlchemy, I wrote these notes in simple words so I don’t fool myself into thinking I understand more than I actually do. This is not a guide. It is a learning reflection.&lt;/p&gt;




&lt;h2&gt;
  
  
  What SQLAlchemy Is (in simple terms)
&lt;/h2&gt;

&lt;p&gt;SQLAlchemy is a Python library used to work with relational databases.&lt;/p&gt;

&lt;p&gt;At first, I thought ORM means “no SQL”. SQLAlchemy proved that idea wrong.&lt;/p&gt;

&lt;p&gt;With SQLAlchemy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SQL is still important&lt;/li&gt;
&lt;li&gt;Tables and relations still matter&lt;/li&gt;
&lt;li&gt;Python objects are optional, not mandatory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It does not hide the database. It exposes it carefully.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Real Issue with “Database Abstraction”
&lt;/h2&gt;

&lt;p&gt;Many tools try to make databases feel invisible:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No SQL&lt;/li&gt;
&lt;li&gt;No schema thinking&lt;/li&gt;
&lt;li&gt;No joins or constraints visible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This feels comfortable but breaks reality.&lt;/p&gt;

&lt;p&gt;Relational databases are powerful because they are strict:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Schemas exist for a reason&lt;/li&gt;
&lt;li&gt;Relations are explicit&lt;/li&gt;
&lt;li&gt;SQL has rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Objects want flexibility. Databases demand accuracy. This conflict always exists.&lt;/p&gt;

&lt;p&gt;SQLAlchemy does not try to escape this conflict.&lt;/p&gt;




&lt;h2&gt;
  
  
  SQLAlchemy’s Core Philosophy
&lt;/h2&gt;

&lt;p&gt;SQLAlchemy does not try to protect the developer from the database.&lt;/p&gt;

&lt;p&gt;Its thinking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You must understand relations&lt;/li&gt;
&lt;li&gt;You must see SQL&lt;/li&gt;
&lt;li&gt;Automation should reduce repetition, not thinking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is why SQLAlchemy calls itself a &lt;strong&gt;toolkit&lt;/strong&gt;, not a framework.&lt;/p&gt;

&lt;p&gt;It allows abstraction to leak:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can see what’s happening&lt;/li&gt;
&lt;li&gt;You can control behavior&lt;/li&gt;
&lt;li&gt;Nothing is forced or hidden&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Core vs ORM (This Took Time to Click)
&lt;/h2&gt;

&lt;p&gt;SQLAlchemy is split into two layers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Core
&lt;/h3&gt;

&lt;p&gt;Core is the foundation.&lt;/p&gt;

&lt;p&gt;It handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database driver communication&lt;/li&gt;
&lt;li&gt;SQL construction&lt;/li&gt;
&lt;li&gt;Table and column definitions&lt;/li&gt;
&lt;li&gt;Connections and execution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Important points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Core works without ORM&lt;/li&gt;
&lt;li&gt;Core stays close to SQL&lt;/li&gt;
&lt;li&gt;Core is always available&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This cleared my confusion that SQLAlchemy equals ORM.&lt;/p&gt;




&lt;h3&gt;
  
  
  ORM
&lt;/h3&gt;

&lt;p&gt;ORM is built on top of Core.&lt;/p&gt;

&lt;p&gt;It adds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mapping Python classes to tables&lt;/li&gt;
&lt;li&gt;Identity tracking&lt;/li&gt;
&lt;li&gt;Change tracking and persistence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key idea:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ORM is optional&lt;/li&gt;
&lt;li&gt;ORM never blocks access to Core&lt;/li&gt;
&lt;li&gt;You can drop down anytime&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This separation feels honest.&lt;/p&gt;




&lt;h2&gt;
  
  
  Cost of This Design
&lt;/h2&gt;

&lt;p&gt;Because everything is layered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Many function calls happen&lt;/li&gt;
&lt;li&gt;Python function calls are slow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SQLAlchemy reduces this by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Optimizing hot paths&lt;/li&gt;
&lt;li&gt;Inlining logic&lt;/li&gt;
&lt;li&gt;Using C extensions where needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The design stays clean instead of being rewritten in low-level code.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why DBAPI Alone Is Not Enough
&lt;/h2&gt;

&lt;p&gt;DBAPI is only a loose specification.&lt;/p&gt;

&lt;p&gt;Different drivers behave differently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unicode handling differs&lt;/li&gt;
&lt;li&gt;Binary handling differs&lt;/li&gt;
&lt;li&gt;Parameter styles differ&lt;/li&gt;
&lt;li&gt;Getting last inserted ID differs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This inconsistency is dangerous.&lt;/p&gt;

&lt;p&gt;SQLAlchemy exists to normalize these differences.&lt;/p&gt;




&lt;h2&gt;
  
  
  Engine, Connection, Result (Mental Model)
&lt;/h2&gt;

&lt;p&gt;SQLAlchemy wraps raw database access into clear layers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Engine&lt;/strong&gt;&lt;br&gt;
Entry point. Knows which database and driver to use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Connection&lt;/strong&gt;&lt;br&gt;
Represents one actual database connection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;br&gt;
Wraps returned rows and metadata cleanly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Direct DBAPI usage disappears.&lt;/p&gt;




&lt;h2&gt;
  
  
  Dialect (The Key Concept)
&lt;/h2&gt;

&lt;p&gt;Dialect was the hardest idea to understand.&lt;/p&gt;

&lt;p&gt;A dialect defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How SQL should look for a database&lt;/li&gt;
&lt;li&gt;Driver-specific behavior&lt;/li&gt;
&lt;li&gt;Type conversions&lt;/li&gt;
&lt;li&gt;Parameter formatting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each dialect targets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One database&lt;/li&gt;
&lt;li&gt;One driver&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This explains how SQLAlchemy supports many databases cleanly.&lt;/p&gt;




&lt;h2&gt;
  
  
  ExecutionContext
&lt;/h2&gt;

&lt;p&gt;Every time a query runs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A short-lived execution object is created&lt;/li&gt;
&lt;li&gt;Runtime details are handled there&lt;/li&gt;
&lt;li&gt;SQL, parameters, and results are connected&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dialect defines rules.&lt;br&gt;
ExecutionContext applies them at runtime.&lt;/p&gt;




&lt;h2&gt;
  
  
  Handling Drivers That Support Many Databases
&lt;/h2&gt;

&lt;p&gt;Some drivers talk to many databases.&lt;/p&gt;

&lt;p&gt;SQLAlchemy handles this by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sharing common behavior&lt;/li&gt;
&lt;li&gt;Adding database-specific logic only where required&lt;/li&gt;
&lt;/ul&gt;

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




&lt;h2&gt;
  
  
  Final Understanding
&lt;/h2&gt;

&lt;p&gt;The main thing I learned:&lt;/p&gt;

&lt;p&gt;Relational databases are strict by nature.&lt;br&gt;
SQLAlchemy does not pretend otherwise.&lt;/p&gt;

&lt;p&gt;Instead, it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Makes rules visible&lt;/li&gt;
&lt;li&gt;Automates repetitive work&lt;/li&gt;
&lt;li&gt;Keeps control with the developer&lt;/li&gt;
&lt;li&gt;Scales from raw SQL to ORM smoothly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This design feels realistic, not magical.&lt;/p&gt;

</description>
      <category>sqlalchemy</category>
      <category>python</category>
      <category>backend</category>
      <category>database</category>
    </item>
  </channel>
</rss>
