<?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: Rinaldo Bonazzo</title>
    <description>The latest articles on DEV Community by Rinaldo Bonazzo (@rinaldo_bonazzo_2454ab629).</description>
    <link>https://dev.to/rinaldo_bonazzo_2454ab629</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%2F3624596%2F0a38353e-ad55-41a2-a4df-19c902e2d3bd.jpg</url>
      <title>DEV Community: Rinaldo Bonazzo</title>
      <link>https://dev.to/rinaldo_bonazzo_2454ab629</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rinaldo_bonazzo_2454ab629"/>
    <language>en</language>
    <item>
      <title>The Data Ferryman</title>
      <dc:creator>Rinaldo Bonazzo</dc:creator>
      <pubDate>Fri, 04 Dec 2026 14:04:25 +0000</pubDate>
      <link>https://dev.to/rinaldo_bonazzo_2454ab629/the-data-ferryman-mmg</link>
      <guid>https://dev.to/rinaldo_bonazzo_2454ab629/the-data-ferryman-mmg</guid>
      <description>&lt;p&gt;I hesitated for an hour before typing &lt;code&gt;ALTER TABLE users ADD COLUMN is_archived BOOLEAN&lt;/code&gt;. The failures came quietly: the ORM defaulted it to &lt;code&gt;None&lt;/code&gt;, the serializer dropped it, the TypeScript build fell over.&lt;/p&gt;

&lt;p&gt;The column took five minutes. Convincing the ORM, the serializer and the frontend that they were all talking about the same column took two days.&lt;/p&gt;

&lt;p&gt;Here is the same feature twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ferryman version
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# BEFORE — everyone does a bit of everything&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;archive_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SELECT * FROM users WHERE id = %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;                       &lt;span class="c1"&gt;# the API layer will turn this into 404&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"UPDATE users SET is_archived = true WHERE id = %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"is_archived"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;   &lt;span class="c1"&gt;# the table, wearing a JSON hat&lt;/span&gt;

&lt;span class="nd"&gt;@app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/users/{user_id}/archive"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;archive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;archive_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;HTTPException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;                           &lt;span class="c1"&gt;# the shape of the DB leaks to the client&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three decisions are hidden in nine lines: what "archived" means (a &lt;code&gt;true&lt;/code&gt; with no timestamp), what "missing" means (Python's &lt;code&gt;None&lt;/code&gt;), and what the client is promised (the entire row). Change one and you find out what breaks in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  The boundary version
&lt;/h2&gt;

&lt;p&gt;The database defends the data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- no user is archived without a timestamp&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;archived_at&lt;/span&gt; &lt;span class="kt"&gt;timestamptz&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;archived_needs_time&lt;/span&gt;
  &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;is_archived&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;archived_at&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python defends the domain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;archive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UserId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;              &lt;span class="c1"&gt;# the domain decides what "missing" means&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;UserNotFound&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;archive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                        &lt;span class="c1"&gt;# the rule lives here, once&lt;/span&gt;
    &lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The API defends the contract:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserArchived&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;            &lt;span class="c1"&gt;# not the table, a promise&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;archived_at&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The difference: a &lt;code&gt;CHECK&lt;/code&gt; constraint rejects a half-archived row, and &lt;code&gt;response_model&lt;/code&gt; strips anything the client wasn't promised. The machine enforces the boundary, not discipline.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three boundaries
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Postgres&lt;/strong&gt; owns the truth of the data: types, constraints, relations. If Python is validating what a &lt;code&gt;CHECK&lt;/code&gt; could reject, you're writing the same rule twice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Python&lt;/strong&gt; owns the truth of the domain: rules, flows, decisions. If your Python collapses into SELECT → dict → transform → dict → INSERT, you have replaced a JOIN with a loop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The APIs&lt;/strong&gt; own the truth of the contract: what you promise, what you accept, what you hide. If your JSON mirrors the table, every refactor is a breaking change.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to tell you need this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You hesitate before adding a column.&lt;/li&gt;
&lt;li&gt;Nobody can say where a business rule lives, because it lives in all three.&lt;/li&gt;
&lt;li&gt;Every change touches five files to do one thing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two out of three, and it's no longer a smell. It's architecture telling you a boundary is missing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to start
&lt;/h2&gt;

&lt;p&gt;You don't rewrite the system. You add one boundary at a time, starting where the pain is loudest.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Find the rule written twice.&lt;/strong&gt; Grep for the same validation in SQL, in Python, in the API layer. Pick one home — usually the constraint — and delete the copies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Name the rule.&lt;/strong&gt; If a business rule lives inside a loop as an &lt;code&gt;if&lt;/code&gt;, move it into a method with a name (&lt;code&gt;is_overdue&lt;/code&gt;, &lt;code&gt;archive&lt;/code&gt;) and give it a test. The name is the boundary.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Declare the contract.&lt;/strong&gt; Add &lt;code&gt;response_model&lt;/code&gt; (or its equivalent in your framework) to every endpoint that returns a row. Five lines, and an entire class of "we didn't know the client read that field" disappears.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Start with the column that scares you. If the change stops surprising you afterwards, you have found the thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs
&lt;/h2&gt;

&lt;p&gt;This costs you something: a constraint to write, a method to name, a model to declare. In exchange, the invisible ripple effects become visible — and then they stop existing. The fragility you feel is not in the problem you are solving. It's in the three separate truths you maintain by hand.&lt;/p&gt;

&lt;p&gt;Stop being a ferryman. Become the boundary.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Published on &lt;a href="https://rinaldosblog.dev" rel="noopener noreferrer"&gt;blog&lt;/a&gt; — comments and corrections welcome.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>postgressql</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
