<?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: Hugo do Carmo</title>
    <description>The latest articles on DEV Community by Hugo do Carmo (@hugodcarmo).</description>
    <link>https://dev.to/hugodcarmo</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%2F260299%2Fc7a46401-8e5d-4701-b8f4-1729984c6a70.jpg</url>
      <title>DEV Community: Hugo do Carmo</title>
      <link>https://dev.to/hugodcarmo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hugodcarmo"/>
    <language>en</language>
    <item>
      <title>CEBIL: A Simple Framework to Reduce Operational Risk</title>
      <dc:creator>Hugo do Carmo</dc:creator>
      <pubDate>Wed, 11 Nov 2026 11:24:58 +0000</pubDate>
      <link>https://dev.to/hugodcarmo/-cebil-a-simple-framework-to-reduce-operational-risk-4i6p</link>
      <guid>https://dev.to/hugodcarmo/-cebil-a-simple-framework-to-reduce-operational-risk-4i6p</guid>
      <description>&lt;h2&gt;
  
  
  The problem: which bug do we fix first?
&lt;/h2&gt;

&lt;p&gt;Most backlogs put a typo in a log message and a double-charge bug in the same list. Both are "bugs", and both can have a small title. Without a shared model, the order depends on who shouts loudest.&lt;/p&gt;

&lt;p&gt;CEBIL is a small scoring model for operational risk. You score each component once, and then you score each ticket in a few seconds, using the score of its component. It helps answer three questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is this component important to everyone, or only to a niche?&lt;/li&gt;
&lt;li&gt;If it fails, will anyone notice, and how bad is it?&lt;/li&gt;
&lt;li&gt;Among the open tickets, which one removes the most risk for the least work?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CEBIL stands for &lt;strong&gt;C&lt;/strong&gt;riticality, &lt;strong&gt;E&lt;/strong&gt;xposure, &lt;strong&gt;B&lt;/strong&gt;usiness visibility, &lt;strong&gt;I&lt;/strong&gt;mpact and &lt;strong&gt;L&lt;/strong&gt;egal. Three more attributes complete the model: &lt;strong&gt;S&lt;/strong&gt;tability, &lt;strong&gt;N&lt;/strong&gt;ature and Comple*&lt;em&gt;X&lt;/em&gt;*ity. I explain every letter below.&lt;/p&gt;

&lt;p&gt;This model is for triage of operational work: bugs, incidents and reliability tasks. It is not a tool to rank new features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1: The alternatives, and where they fall short
&lt;/h2&gt;

&lt;p&gt;Several good frameworks already exist. None of them was designed for operational risk, so each one leaves a gap.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Framework&lt;/th&gt;
&lt;th&gt;What it scores&lt;/th&gt;
&lt;th&gt;Good for&lt;/th&gt;
&lt;th&gt;Gap for operational risk&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;RICE&lt;/td&gt;
&lt;td&gt;Reach × Impact × Confidence ÷ Effort&lt;/td&gt;
&lt;td&gt;Ranking new features&lt;/td&gt;
&lt;td&gt;"Impact" describes gain, not damage. There is no idea of failure or likelihood.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WSJF&lt;/td&gt;
&lt;td&gt;(Business value + Time criticality + Risk reduction or opportunity) ÷ Job size&lt;/td&gt;
&lt;td&gt;Sequencing work across a portfolio&lt;/td&gt;
&lt;td&gt;Risk is one input among three, so reliability work competes with features in a single ratio.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost of delay&lt;/td&gt;
&lt;td&gt;Economic loss per unit of time&lt;/td&gt;
&lt;td&gt;Deciding what to expedite&lt;/td&gt;
&lt;td&gt;It needs money estimates, which are hard to guess for small bugs.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FMEA&lt;/td&gt;
&lt;td&gt;Severity × Occurrence × Detection&lt;/td&gt;
&lt;td&gt;Analysing how a component can fail&lt;/td&gt;
&lt;td&gt;It works per failure mode, so it is too heavy to run on every ticket.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;CEBIL borrows from all four: risk as consequence × likelihood (FMEA), value over effort (RICE and WSJF), and the idea that some work skips the queue (expedite, in cost of delay). Two things are different. The component scores are static, so a ticket only needs two new inputs. And a few rules override the ratio on purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 2: The framework
&lt;/h2&gt;

&lt;p&gt;CEBIL works in two stages. The component stage is static and reviewed every quarter. The ticket stage is fast and happens for every bug or change.&lt;/p&gt;

&lt;h3&gt;
  
  
  a) Component: the letters
&lt;/h3&gt;

&lt;p&gt;Five letters measure the consequence of a failure. Each one is a score from 0 to 3, except Legal, which goes from 0 to 2.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Letter&lt;/th&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;0&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;th&gt;2&lt;/th&gt;
&lt;th&gt;3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;I&lt;/strong&gt; Impact&lt;/td&gt;
&lt;td&gt;What happens in a typical failure?&lt;/td&gt;
&lt;td&gt;No visible impact&lt;/td&gt;
&lt;td&gt;Minor inconvenience&lt;/td&gt;
&lt;td&gt;Part of a flow degrades&lt;/td&gt;
&lt;td&gt;Core flow blocked, or data corrupted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;C&lt;/strong&gt; Criticality and recovery&lt;/td&gt;
&lt;td&gt;Is it a hard dependency, and how hard is recovery? Use the worse answer.&lt;/td&gt;
&lt;td&gt;Optional, and it recovers by itself&lt;/td&gt;
&lt;td&gt;Helper, or easy manual recovery&lt;/td&gt;
&lt;td&gt;Replaceable, or recovery needs coordination&lt;/td&gt;
&lt;td&gt;Hard dependency, or recovery needs data fixes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;E&lt;/strong&gt; Exposure&lt;/td&gt;
&lt;td&gt;Who is affected?&lt;/td&gt;
&lt;td&gt;Internal only&lt;/td&gt;
&lt;td&gt;Small group&lt;/td&gt;
&lt;td&gt;Many users or teams&lt;/td&gt;
&lt;td&gt;Everyone, or external parties&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;B&lt;/strong&gt; Business visibility&lt;/td&gt;
&lt;td&gt;How fast does the business notice?&lt;/td&gt;
&lt;td&gt;Invisible&lt;/td&gt;
&lt;td&gt;Noticed eventually&lt;/td&gt;
&lt;td&gt;Support tickets&lt;/td&gt;
&lt;td&gt;Immediate calls, legal or financial impact&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;L&lt;/strong&gt; Legal&lt;/td&gt;
&lt;td&gt;Is there regulatory, contractual or audit risk?&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Possibly risky&lt;/td&gt;
&lt;td&gt;Absolutely risky&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three more attributes are not part of the consequence sum. Each has a different job.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Letter&lt;/th&gt;
&lt;th&gt;Job&lt;/th&gt;
&lt;th&gt;Low&lt;/th&gt;
&lt;th&gt;Middle&lt;/th&gt;
&lt;th&gt;High&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;S&lt;/strong&gt; Stability&lt;/td&gt;
&lt;td&gt;Likelihood. It multiplies the consequence.&lt;/td&gt;
&lt;td&gt;1: stable, rare incidents&lt;/td&gt;
&lt;td&gt;2: occasional failures&lt;/td&gt;
&lt;td&gt;3: frequently flaky&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;N&lt;/strong&gt; Nature&lt;/td&gt;
&lt;td&gt;Worst case. It sets a minimum class.&lt;/td&gt;
&lt;td&gt;0: life goes on if it fails, maybe annoying&lt;/td&gt;
&lt;td&gt;1: it may cause a catastrophe&lt;/td&gt;
&lt;td&gt;2: imminent catastrophe if it fails&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;X&lt;/strong&gt; Complexity&lt;/td&gt;
&lt;td&gt;Effort anchor. It is stored, and used only for tickets.&lt;/td&gt;
&lt;td&gt;1: simple, anyone on the team can change it&lt;/td&gt;
&lt;td&gt;2: several business rules, or domain knowledge needed&lt;/td&gt;
&lt;td&gt;3: hard algorithm, or only one or two people can change it safely&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two details are easy to miss. C takes the worse of its two halves, so a stateless hard dependency and an easy-to-replay but critical job both score high. And N describes the worst case, while I describes the typical case.&lt;/p&gt;

&lt;h3&gt;
  
  
  b) Ticket: the letters
&lt;/h3&gt;

&lt;p&gt;A ticket inherits everything from its component. Only two inputs are new.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Letter&lt;/th&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Values&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;M&lt;/strong&gt; Manifestation&lt;/td&gt;
&lt;td&gt;How much of the component's worst case does this bug cause?&lt;/td&gt;
&lt;td&gt;Cosmetic ×0.25: no effect on the function, like a log typo. Partial ×0.5: an edge case, a workaround exists, or a small share of traffic. Core ×1: it hits the failure that made N high.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;F&lt;/strong&gt; Effort&lt;/td&gt;
&lt;td&gt;How long will the fix take?&lt;/td&gt;
&lt;td&gt;1: under a day. 2: a few days. 3: a week or more.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  c) Equations, floors, guardrails and implicit rules
&lt;/h3&gt;

&lt;p&gt;The component equations are simple arithmetic. The ticket equation adds the manifestation and the effort.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;COMPONENT
Consequence = I + C + E + B + L          (0 to 14)
Risk        = Consequence × S            (0 to 42)
Class       = max( band(Risk), floor(N) )

TICKET
F_used      = max( F_estimated, floor(X) )   (X = 3 means at least 2)
Priority    = Risk × M ÷ F_used
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The class comes from two lookups: the band of the Risk, and the floor from N. The higher result wins.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Risk&lt;/th&gt;
&lt;th&gt;Band&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0 to 7&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8 to 17&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;18 to 28&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;29 to 42&lt;/td&gt;
&lt;td&gt;Critical&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;N&lt;/th&gt;
&lt;th&gt;Floor on the class&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;At least High&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;At least Medium&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;No floor, Risk decides&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implicit rules at component level&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;N is a floor, not part of the sum.&lt;/strong&gt; "Imminent catastrophe" overlaps with I = 3 and C = 3, so adding it would count the same thing twice. As a floor, it also stops a very stable component from multiplying down to Medium.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiplying by S removes trivial components.&lt;/strong&gt; If the consequence is 0, Risk is 0, however flaky the component is.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch your N = 2 count.&lt;/strong&gt; If more than about 10 to 15 percent of your components are N = 2, the label has lost its meaning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;S is reviewed on a schedule.&lt;/strong&gt; Review it every quarter, or when bugs cluster. For a new component with no history, start from complexity: X = 3 starts at S = 2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;X stays out of Risk and Class.&lt;/strong&gt; Complexity already appears as likelihood through S, and a complex component is not more important only because it is complex.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key-person rule.&lt;/strong&gt; X = 3 together with N of 1 or 2 means you need a second owner, documentation and a runbook.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implicit rules at ticket level&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Class never changes between tickets of one component.&lt;/strong&gt; Class says the component needs attention. Priority orders the work inside it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;X floors the effort.&lt;/strong&gt; A "one-line fix" in a complex component is rarely a one-hour job, because someone must load the context and test the rules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Drop-everything guardrail.&lt;/strong&gt; If M is Core and N is 2, the ticket goes to the top, whatever the Priority. Dividing by effort is fine for normal work, but it must not push a data-corrupting bug behind quick wins.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Effort never changes the class.&lt;/strong&gt; A six-month fix on a core component is still High.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A bug is evidence about S, not a change to S.&lt;/strong&gt; Count bugs per component and use them in the quarterly review.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write the reason for M on the ticket.&lt;/strong&gt; This stops authors from inflating M to jump the queue, and it gives reviewers something to challenge.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ticket to component mapping decides everything.&lt;/strong&gt; A wrong mapping silently gives the wrong Risk. If the mapping is unclear, ask a human.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Part 3: Component evaluation example
&lt;/h2&gt;

&lt;p&gt;Take a payment system built on Stripe with five components. The scorecard below gives each one a Class, and one of them shows the N floor at work.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;I&lt;/th&gt;
&lt;th&gt;C&lt;/th&gt;
&lt;th&gt;E&lt;/th&gt;
&lt;th&gt;B&lt;/th&gt;
&lt;th&gt;L&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;th&gt;S&lt;/th&gt;
&lt;th&gt;Risk&lt;/th&gt;
&lt;th&gt;N&lt;/th&gt;
&lt;th&gt;Class&lt;/th&gt;
&lt;th&gt;X&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;PaymentService&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;High (floor)&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PaymentRetryJob&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WebhookEventSender&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logging&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MetricsExporter&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;What the scorecard shows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PaymentService&lt;/strong&gt; is very stable, so Risk is only 14, which is Medium. Because N = 2, the class rises to High. Without the floor, the most important component would sit in the same band as the webhook sender. It also has X = 3 and N of 2, so the key-person rule applies: it needs a second owner and a runbook.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PaymentRetryJob&lt;/strong&gt; is High on Risk alone (9 × 2 = 18). Stripe declines and rate limits make it flaky, which is why S is 2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logging&lt;/strong&gt; gets L = 1 because payment logs can matter in an audit. Nothing else keeps it above Low.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MetricsExporter&lt;/strong&gt; has a consequence of 0, so Risk is 0 even though S is 2. A flaky component that nobody needs cannot climb the bands.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Part 4: Ticket evaluation example
&lt;/h2&gt;

&lt;p&gt;Now three bugs arrive in the same component, PaymentService. All three inherit Consequence 14, S = 1, Risk 14, N = 2, Class High and X = 3. Only M and F make them different. Because X = 3, the effort is never below 2.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Bug&lt;/th&gt;
&lt;th&gt;M&lt;/th&gt;
&lt;th&gt;F estimated&lt;/th&gt;
&lt;th&gt;F used&lt;/th&gt;
&lt;th&gt;Calculation&lt;/th&gt;
&lt;th&gt;Priority&lt;/th&gt;
&lt;th&gt;Guardrail&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A. Duplicate charge when a client retries after a Stripe timeout&lt;/td&gt;
&lt;td&gt;Core ×1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;14 × 1 ÷ 2&lt;/td&gt;
&lt;td&gt;7.0&lt;/td&gt;
&lt;td&gt;Drop everything&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B. 3-D Secure redirect fails for about 2% of cards, and the customer can retry&lt;/td&gt;
&lt;td&gt;Partial ×0.5&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;14 × 0.5 ÷ 3&lt;/td&gt;
&lt;td&gt;2.3&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C. Typo in the payment confirmation label&lt;/td&gt;
&lt;td&gt;Cosmetic ×0.25&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;14 × 0.25 ÷ 2&lt;/td&gt;
&lt;td&gt;1.8&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three things to notice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Bug A skips the ratio.&lt;/strong&gt; M is Core and N is 2, so the guardrail puts it first. A cheap quick win must never be placed above a bug that charges customers twice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The X floor changes the order of B and C.&lt;/strong&gt; Bug C looks like a one-hour fix, but the floor sets F to 2, so its priority is 1.8 and not 3.5. Without the floor, a typo would jump ahead of a real customer-facing defect.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The class stays High for all three.&lt;/strong&gt; Class tells you the component needs attention. Priority tells you the order of the work inside it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Part 5: Using AI to apply the framework
&lt;/h2&gt;

&lt;p&gt;You can automate most of the scoring, but the AI agent should only propose the inputs. Ordinary code should compute every number, because the formulas are plain arithmetic. This keeps results repeatable, and it makes the guardrail a hard-coded &lt;code&gt;if&lt;/code&gt;, not something a model might forget.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What an agent can score well&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Letter&lt;/th&gt;
&lt;th&gt;How much to trust the agent&lt;/th&gt;
&lt;th&gt;Evidence it can use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C, E&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Dependency graph, traffic, number of consumers, public or internal endpoints&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S&lt;/td&gt;
&lt;td&gt;High, but compute it&lt;/td&gt;
&lt;td&gt;Incident history, error rates and past bug tickets per component&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;X&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;Number of business-rule branches, how many people changed the code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;I&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;Code and docs, but worst-case thinking needs a review&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B, L, N&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;It can suggest with cited evidence, but a human decides&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M&lt;/td&gt;
&lt;td&gt;Good fit&lt;/td&gt;
&lt;td&gt;Ticket text plus component description, with a one-line reason&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;F&lt;/td&gt;
&lt;td&gt;Weak&lt;/td&gt;
&lt;td&gt;Better to use the cycle time of similar past tickets, floored by X&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;A possible setup&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Keep a component registry in git, with the scores, the evidence, the owner and the last review date.&lt;/li&gt;
&lt;li&gt;Run a scheduled agent every quarter, and when bugs cluster. It opens a pull request with proposed score changes and evidence. A human reviews and merges it.&lt;/li&gt;
&lt;li&gt;When a ticket arrives, the agent maps it to a component and proposes M and F. A script then computes the Priority and writes it to a custom field on the ticket.&lt;/li&gt;
&lt;li&gt;Keep the formulas, bands, floors and the guardrail in code, not in the prompt.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Guardrails for the agent&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Put your score tables and examples in the prompt, and ask for a quote of the evidence behind every score. Without anchors, scores drift between runs.&lt;/li&gt;
&lt;li&gt;Score each component twice and compare. If the two runs disagree, the rubric is probably unclear.&lt;/li&gt;
&lt;li&gt;Start in shadow mode for a few sprints. Write the priority, but do not let it reorder anything, and compare it with how the team would rank the backlog.&lt;/li&gt;
&lt;li&gt;Show the reason for M on the ticket and keep a human override, because people can inflate M to jump the queue.&lt;/li&gt;
&lt;li&gt;Send tickets with a low-confidence component mapping to a person. A wrong mapping is worse than no score.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Part 6: What this model lacks
&lt;/h2&gt;

&lt;p&gt;CEBIL is a triage tool, and it has real limits. You should know them before you adopt it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No time dimension.&lt;/strong&gt; Cost of delay is about how loss grows over time, including fixed deadlines. CEBIL has no deadline, so a bug that becomes expensive in ten days looks the same as one that does not. If you need this, add a deadline flag that works like the guardrail.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No confidence term.&lt;/strong&gt; RICE reduces the score of items with uncertain estimates. In CEBIL, a wrong M or a wrong component mapping goes straight into the Priority. The human override and the escalation of unclear mappings are the only protection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No upside.&lt;/strong&gt; The model measures only what can break. It cannot rank new features, so do not use it for that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calibration is your work.&lt;/strong&gt; RICE and WSJF have scales that many people already know. The anchors in this post are my own, so your team must test them on real components and adjust them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiplication can still hide a rare disaster.&lt;/strong&gt; The N floor is the answer, but it depends on honest scoring of N, and honest scoring is hard.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A practical way to combine them: use RICE or WSJF for features, use CEBIL for bugs and reliability work, and feed a component's Risk into WSJF as the risk-reduction input when both kinds of work compete.&lt;/p&gt;

&lt;h2&gt;
  
  
  P.S. Put the CEBIL score in the code
&lt;/h2&gt;

&lt;p&gt;I suggest adding a CEBIL comment at the top of the main file of each component, with the date of the last review. Then the risk is visible exactly where people make changes, and a reviewer can see how old the score is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * CEBIL - reviewed 2026-11-11 - next review 2027-02-11
 * Component: PaymentService (Stripe charges)
 * I:3 C:3 E:3 B:3 L:2  -&amp;gt; Consequence 14
 * S:1  N:2  X:3        -&amp;gt; Risk 14, Class High (N = 2 floor)
 * Owner: payments-team
 * Rules: Core bugs here are drop-everything.
 *        Effort estimates start at 2 days or more (X = 3).
 *        Changes need a second reviewer (N = 2).
 */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This small habit helps in four ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Review scope.&lt;/strong&gt; A pull request that touches a file with N = 2 can require a second reviewer, and a file with L = 2 can require an audit check.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Honest dates.&lt;/strong&gt; A score is a claim about the code, and code changes. A CI job can read the header and fail when the review date is older than 90 days.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feed for the agent.&lt;/strong&gt; The same header can be the source of the component registry from Part 5, so scores live next to the code and not in a separate document that nobody opens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster onboarding.&lt;/strong&gt; A new developer sees in ten seconds that this file is not a normal place for a quick fix.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you try CEBIL, I would like to hear which scores felt wrong. Those are the anchors that need work.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>sre</category>
      <category>management</category>
      <category>productivity</category>
    </item>
    <item>
      <title>One GPG key per AI agent: why and how (Claude Code + Codex)</title>
      <dc:creator>Hugo do Carmo</dc:creator>
      <pubDate>Tue, 10 Nov 2026 02:43:24 +0000</pubDate>
      <link>https://dev.to/hugodcarmo/one-gpg-key-per-ai-agent-why-and-how-claude-code-codex-1mne</link>
      <guid>https://dev.to/hugodcarmo/one-gpg-key-per-ai-agent-why-and-how-claude-code-codex-1mne</guid>
      <description>&lt;p&gt;If an AI agent writes your commits, it should sign them with its own GPG key, not with yours. A friend who works at a big tech company told me this is now an internal rule there, and after thinking about it for a while, I agree with it.&lt;/p&gt;

&lt;p&gt;Most of us barely write commits by hand anymore. Claude Code, Codex and other agents do the typing, and we review. But many people still let the agent sign with their personal key, so every commit looks the same: "signed by me". In this post I explain why that is a problem, and then I show you, step by step, how to give Claude Code and Codex their own keys and register them on GitHub.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why give each agent its own key?
&lt;/h2&gt;

&lt;p&gt;There are more reasons than the three below, but these are the ones you will run into most often.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The agent shouldn't have your private key
&lt;/h3&gt;

&lt;p&gt;This is the most important reason. To sign commits with your key, the agent needs access to it. Agents often run in places that are much less safe than your laptop or your hardware token: a sandbox, a CI runner, a cloud VM.&lt;/p&gt;

&lt;p&gt;Agents can also be tricked. A prompt injection hidden in an issue, a README, a dependency or a web page can make an agent do things you never asked for. If that agent holds your key, it can create commits that look exactly like commits you personally signed. Nobody can tell the difference.&lt;/p&gt;

&lt;p&gt;With a separate key, the damage is limited. If the agent key leaks, you revoke that one key. Your own key, your identity and your other projects stay safe.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Audits and incident response get easier
&lt;/h3&gt;

&lt;p&gt;Sooner or later something goes wrong: a bug in production, a security hole, a strange change nobody remembers making. When that happens, the first question is "where did this come from?"&lt;/p&gt;

&lt;p&gt;If each agent signs with its own key, the answer is in &lt;code&gt;git log&lt;/code&gt;. You can filter all commits made by Claude Code, or only the ones made by Codex, or only the ones made during the week an agent was acting strangely. With one shared key, all of that history is mixed together, and you have to guess.&lt;/p&gt;

&lt;p&gt;This also helps with compliance. More and more companies are being asked how they track AI-generated code. "Every agent commit is signed with a dedicated key" is a simple and clear answer.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Signatures are about who vouches for the code, not who typed it
&lt;/h3&gt;

&lt;p&gt;A common reaction is: "Nobody writes code by hand anymore, so why separate anything?" I think it is the opposite. Because almost everything is generated now, the useful question is no longer "who typed this?". It is "did a human look at this and take responsibility for it?"&lt;/p&gt;

&lt;p&gt;With separate keys, each signature means something clear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Agent key:&lt;/strong&gt; an agent produced this commit, in a session started by this person.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your key:&lt;/strong&gt; a human reviewed and approved this, for example on the merge or the release.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your personal key becomes rarer, and that makes it more valuable. It works like a sign-off, not like a record of typing. It also lets you write rules such as "commits signed only by an agent key cannot merge to main without a human approval".&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;The plan is simple. Each agent gets:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Its own GPG keyring, in a separate folder, so the agent's &lt;code&gt;gpg&lt;/code&gt; can't even see your personal key.&lt;/li&gt;
&lt;li&gt;Its own email address and name, so its commits are easy to spot.&lt;/li&gt;
&lt;li&gt;A config that tells git to use that key every time the agent commits.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I use Gmail's plus addressing for the emails (&lt;code&gt;you+claude@gmail.com&lt;/code&gt;, &lt;code&gt;you+codex@gmail.com&lt;/code&gt;). Messages still arrive in your normal inbox, so you can verify them on GitHub. Replace &lt;code&gt;you&lt;/code&gt;, &lt;code&gt;Your Name&lt;/code&gt; and &lt;code&gt;/home/YOU&lt;/code&gt; with your own values in all the commands below.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a key for Claude Code
&lt;/h3&gt;

&lt;p&gt;First, create a separate keyring folder. &lt;code&gt;GNUPGHOME&lt;/code&gt; tells &lt;code&gt;gpg&lt;/code&gt; which folder to use, so this key lives apart from your personal one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p ~/.gnupg-claude &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; chmod 700 ~/.gnupg-claude

&lt;span class="nv"&gt;GNUPGHOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.gnupg-claude gpg --batch --pinentry-mode loopback --passphrase &lt;span class="s1"&gt;''&lt;/span&gt; \
  --quick-gen-key &lt;span class="s2"&gt;"Your Name (Claude Code) &amp;lt;you+claude@gmail.com&amp;gt;"&lt;/span&gt; ed25519 sign 1y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few things to notice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No passphrase.&lt;/strong&gt; The agent can't type one, so the key has none. This is acceptable because the key can only sign, it expires, and you can revoke it without touching your own key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ed25519 sign&lt;/code&gt;&lt;/strong&gt; creates a modern, small key that is only allowed to sign.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;1y&lt;/code&gt;&lt;/strong&gt; makes the key expire after one year. Rotating agent keys regularly is a good habit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now find the key ID. It is the part after &lt;code&gt;ed25519/&lt;/code&gt; in the &lt;code&gt;sec&lt;/code&gt; line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;GNUPGHOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.gnupg-claude gpg --list-secret-keys --keyid-format=long
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sec   ed25519/ABCD1234EF567890 2026-11-09 [SC] [expires: 2027-11-09]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example the key ID is &lt;code&gt;ABCD1234EF567890&lt;/code&gt;. Keep it, you will need it in the next steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Register the email and the key on GitHub
&lt;/h3&gt;

&lt;p&gt;GitHub only shows a commit as &lt;strong&gt;Verified&lt;/strong&gt; when two things match: the signature belongs to a GPG key on your account, and the commit email is a verified email on your account. So you need to add both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add the email:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to GitHub → &lt;strong&gt;Settings&lt;/strong&gt; → &lt;strong&gt;Emails&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;you+claude@gmail.com&lt;/code&gt; in &lt;strong&gt;Add email address&lt;/strong&gt; and click &lt;strong&gt;Add&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Open the confirmation email (it lands in your normal Gmail inbox) and click the link.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Add the GPG key.&lt;/strong&gt; First, export the public part of the key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;GNUPGHOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.gnupg-claude gpg --armor --export ABCD1234EF567890
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy everything from &lt;code&gt;-----BEGIN PGP PUBLIC KEY BLOCK-----&lt;/code&gt; to &lt;code&gt;-----END PGP PUBLIC KEY BLOCK-----&lt;/code&gt;. Then:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to GitHub → &lt;strong&gt;Settings&lt;/strong&gt; → &lt;strong&gt;SSH and GPG keys&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;New GPG key&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Give it a clear title, like &lt;code&gt;Claude Code (laptop)&lt;/code&gt;, paste the key and click &lt;strong&gt;Add GPG key&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Import the public key on your machine.&lt;/strong&gt; Your normal keyring (&lt;code&gt;~/.gnupg&lt;/code&gt;) has never seen this key. Without this step, &lt;code&gt;git log --show-signature&lt;/code&gt; in your own terminal says &lt;code&gt;Can't check signature: No public key&lt;/code&gt;, even though the commit is signed correctly. Import only the public part. The private key stays in &lt;code&gt;~/.gnupg-claude&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;GNUPGHOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.gnupg-claude gpg --armor --export ABCD1234EF567890 &lt;span class="o"&gt;|&lt;/span&gt; gpg --import
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Optionally, sign the agent key with your own key. This removes the "key is not certified" warning, and it also records that you authorized this agent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gpg --list-keys ABCD1234EF567890   &lt;span class="c"&gt;# copy the full fingerprint&lt;/span&gt;
gpg --quick-sign-key &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;FINGERPRINT&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Tell Claude Code to use its key
&lt;/h3&gt;

&lt;p&gt;Claude Code adds the variables from the &lt;code&gt;env&lt;/code&gt; block of its settings file to every command it runs. Git (2.31 or newer) can also read config values from environment variables, through &lt;code&gt;GIT_CONFIG_COUNT&lt;/code&gt;, &lt;code&gt;GIT_CONFIG_KEY_n&lt;/code&gt; and &lt;code&gt;GIT_CONFIG_VALUE_n&lt;/code&gt;. Together, this means you don't need to change your global git config at all.&lt;/p&gt;

&lt;p&gt;Add this to &lt;code&gt;~/.claude/settings.json&lt;/code&gt; to apply it everywhere, or to &lt;code&gt;.claude/settings.json&lt;/code&gt; inside a repo to apply it only there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"GNUPGHOME"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/home/YOU/.gnupg-claude"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_AUTHOR_NAME"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Your Name (Claude Code)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_AUTHOR_EMAIL"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"you+claude@gmail.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_COMMITTER_NAME"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Your Name (Claude Code)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_COMMITTER_EMAIL"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"you+claude@gmail.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_CONFIG_COUNT"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_CONFIG_KEY_0"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user.signingkey"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_CONFIG_VALUE_0"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ABCD1234EF567890"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_CONFIG_KEY_1"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"commit.gpgsign"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_CONFIG_VALUE_1"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_CONFIG_KEY_2"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"gpg.format"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"GIT_CONFIG_VALUE_2"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"openpgp"&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;Use an absolute path for &lt;code&gt;GNUPGHOME&lt;/code&gt;, because JSON does not expand &lt;code&gt;~&lt;/code&gt;. If your file already has other settings, just add the &lt;code&gt;env&lt;/code&gt; block next to them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Do the same for Codex
&lt;/h3&gt;

&lt;p&gt;Create a second key in a second keyring. It is the same command as before, with a different folder, name and email:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p ~/.gnupg-codex &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; chmod 700 ~/.gnupg-codex

&lt;span class="nv"&gt;GNUPGHOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.gnupg-codex gpg --batch --pinentry-mode loopback --passphrase &lt;span class="s1"&gt;''&lt;/span&gt; \
  --quick-gen-key &lt;span class="s2"&gt;"Your Name (Codex) &amp;lt;you+codex@gmail.com&amp;gt;"&lt;/span&gt; ed25519 sign 1y

&lt;span class="nv"&gt;GNUPGHOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.gnupg-codex gpg --list-secret-keys --keyid-format=long
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then repeat &lt;strong&gt;Step 2&lt;/strong&gt; with the Codex values: add &lt;code&gt;you+codex@gmail.com&lt;/code&gt; as a verified email on GitHub, add the exported public key as a new GPG key (title it &lt;code&gt;Codex (laptop)&lt;/code&gt;), and import the public key into your local keyring.&lt;/p&gt;

&lt;p&gt;Codex reads its config from &lt;code&gt;~/.codex/config.toml&lt;/code&gt;. The &lt;code&gt;[shell_environment_policy]&lt;/code&gt; section controls the environment of every command Codex runs, and its &lt;code&gt;set&lt;/code&gt; key adds variables to it. Add this, using your Codex key ID and your real home path (TOML does not expand &lt;code&gt;~&lt;/code&gt; either):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[shell_environment_policy.set]&lt;/span&gt;
&lt;span class="na"&gt;GNUPGHOME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"/home/YOU/.gnupg-codex"&lt;/span&gt;

&lt;span class="na"&gt;GIT_AUTHOR_NAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Your Name (Codex)"&lt;/span&gt;
&lt;span class="na"&gt;GIT_AUTHOR_EMAIL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"you+codex@gmail.com"&lt;/span&gt;
&lt;span class="na"&gt;GIT_COMMITTER_NAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Your Name (Codex)"&lt;/span&gt;
&lt;span class="na"&gt;GIT_COMMITTER_EMAIL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"you+codex@gmail.com"&lt;/span&gt;

&lt;span class="na"&gt;GIT_CONFIG_COUNT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"3"&lt;/span&gt;
&lt;span class="na"&gt;GIT_CONFIG_KEY_0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"user.signingkey"&lt;/span&gt;
&lt;span class="na"&gt;GIT_CONFIG_VALUE_0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;CODEX_KEYID&amp;gt;"&lt;/span&gt;
&lt;span class="na"&gt;GIT_CONFIG_KEY_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"commit.gpgsign"&lt;/span&gt;
&lt;span class="na"&gt;GIT_CONFIG_VALUE_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
&lt;span class="na"&gt;GIT_CONFIG_KEY_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gpg.format"&lt;/span&gt;
&lt;span class="na"&gt;GIT_CONFIG_VALUE_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"openpgp"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;GIT_CONFIG_COUNT&lt;/code&gt; is &lt;code&gt;3&lt;/code&gt; because there are three config entries (numbered 0, 1 and 2). The third one, &lt;code&gt;gpg.format = openpgp&lt;/code&gt;, is already git's default. I keep it anyway: if your global git config signs with SSH (&lt;code&gt;gpg.format ssh&lt;/code&gt;), this makes sure the agent still uses its GPG key. If you change the number of entries, change &lt;code&gt;GIT_CONFIG_COUNT&lt;/code&gt; too, or git ignores the extra ones.&lt;/p&gt;

&lt;p&gt;If your file already has &lt;code&gt;set = { ... }&lt;/code&gt; written inline under &lt;code&gt;[shell_environment_policy]&lt;/code&gt;, remove it. TOML does not allow the same table to be defined twice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why not a wrapper script?&lt;/strong&gt; You could export these variables in a small script that starts Codex. But Codex has a built-in filter that removes inherited variables with names like &lt;code&gt;*KEY*&lt;/code&gt; or &lt;code&gt;*TOKEN*&lt;/code&gt;, to avoid leaking secrets. &lt;code&gt;GIT_CONFIG_KEY_0&lt;/code&gt; matches that pattern. The variable can disappear silently, and your commits go out unsigned. Values defined with &lt;code&gt;set&lt;/code&gt; are added after that filter, so they are safe. One warning: if you also use &lt;code&gt;include_only&lt;/code&gt; in this section, these variables must be on that list too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Test it
&lt;/h3&gt;

&lt;p&gt;Start a &lt;strong&gt;new&lt;/strong&gt; session of the agent (settings are read at startup), ask it to make a small commit, and then run this in your own terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log --show-signature -1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gpg: Good signature from "Your Name (Claude Code) &amp;lt;you+claude@gmail.com&amp;gt;"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you push, GitHub should show the commit as &lt;strong&gt;Verified&lt;/strong&gt;, with the agent's name as the author.&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Can't check signature: No public key&lt;/code&gt;&lt;/strong&gt;: the commit is signed, but your personal keyring doesn't know the agent's public key. Do the import part of Step 2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;gpg failed to sign the data&lt;/code&gt; inside Codex&lt;/strong&gt;: the Codex sandbox is probably blocking gpg from writing to &lt;code&gt;~/.gnupg-codex&lt;/code&gt;, where gpg-agent keeps its socket and lock files. Add the folder to the sandbox's writable folders (in my config this is &lt;code&gt;writable_roots&lt;/code&gt; under &lt;code&gt;[sandbox_workspace_write]&lt;/code&gt;; check the Codex docs for your version).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The commit is signed with your personal key&lt;/strong&gt;: the agent session started before you changed the settings. Restart it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub shows Unverified&lt;/strong&gt;: the commit email is not a verified email on your account, or the public key was not added. Check both parts of Step 2.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One honest limitation
&lt;/h2&gt;

&lt;p&gt;This setup makes the agent use its own key by default. It does &lt;strong&gt;not&lt;/strong&gt; stop an agent that can run any shell command from reading &lt;code&gt;~/.gnupg&lt;/code&gt; directly. If you want a real guarantee, also block access to that folder with Claude Code's sandbox or permission rules, or run the agent in a container.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;It takes about ten minutes per agent, and you get three things in return: your personal key never leaves your control, you can see in &lt;code&gt;git log&lt;/code&gt; which agent wrote what, and your own signature goes back to meaning "I reviewed this".&lt;/p&gt;

&lt;p&gt;If GPG feels too heavy, git can also sign commits with SSH keys (&lt;code&gt;gpg.format ssh&lt;/code&gt;). The same idea works there: one key per agent, never your own.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>claude</category>
      <category>openai</category>
      <category>containers</category>
    </item>
    <item>
      <title>Where Should the Foreign Key Go?</title>
      <dc:creator>Hugo do Carmo</dc:creator>
      <pubDate>Thu, 23 Jul 2026 02:24:51 +0000</pubDate>
      <link>https://dev.to/hugodcarmo/where-should-the-foreign-key-go-20id</link>
      <guid>https://dev.to/hugodcarmo/where-should-the-foreign-key-go-20id</guid>
      <description>&lt;p&gt;&lt;em&gt;This is Part II of a series about vertical partitioning for large text columns. &lt;a href="https://dev.to/hugodcarmo/when-large-text-belongs-in-a-separate-table-5hfk"&gt;Part I&lt;/a&gt; explains why we separated the large text from the main table.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://dev.to/hugodcarmo/when-large-text-belongs-in-a-separate-table-5hfk"&gt;Part I&lt;/a&gt;, we split one &lt;code&gt;books&lt;/code&gt; table into two tables:&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="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;               &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="no"&gt;AUTO_INCREMENT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;            &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;author&lt;/span&gt;           &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;isbn&lt;/span&gt;             &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;published_year&lt;/span&gt;   &lt;span class="kt"&gt;SMALLINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&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="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;book_contents&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;book_id&lt;/span&gt;     &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;resume&lt;/span&gt;      &lt;span class="kt"&gt;TEXT&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="k"&gt;FOREIGN&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="nf"&gt;books&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;CASCADE&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;The foreign key is in &lt;code&gt;book_contents&lt;/code&gt;, and it points to &lt;code&gt;books&lt;/code&gt;. Part I used this design without explaining it in detail.&lt;/p&gt;

&lt;p&gt;However, we could put the foreign key in the other table. We could add a &lt;code&gt;content_id&lt;/code&gt; column to &lt;code&gt;books&lt;/code&gt; instead. Both designs are valid SQL, but they describe different relationships and create different responsibilities in the application.&lt;/p&gt;

&lt;p&gt;There is also a third design for systems that need to keep several versions of a book's content. We will look at all three options.&lt;/p&gt;

&lt;h2&gt;
  
  
  Option A: Put the foreign key in the content table
&lt;/h2&gt;

&lt;p&gt;This is the design used in Part I:&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="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;      &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="no"&gt;AUTO_INCREMENT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;   &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&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="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;book_contents&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;book_id&lt;/span&gt;  &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;resume&lt;/span&gt;   &lt;span class="kt"&gt;TEXT&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="k"&gt;FOREIGN&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="nf"&gt;books&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;CASCADE&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;Here, &lt;code&gt;book_contents.book_id&lt;/code&gt; is both a primary key and a foreign key.&lt;/p&gt;

&lt;p&gt;The foreign key connects the content to a book. The primary key guarantees that each book can have no more than one content row. The content row uses the same identity as the book because it is an extension of that book.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a book
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;books&lt;/code&gt; table does not depend on &lt;code&gt;book_contents&lt;/code&gt;. We can create a book first and add its content later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'title'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Dune'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'author'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Frank Herbert'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&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="c1"&gt;// We can create the content now, later, or not at all.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is useful when the content is optional or is not ready when the book is created. A book without content is simply a row in &lt;code&gt;books&lt;/code&gt; with no related row in &lt;code&gt;book_contents&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With Eloquent, the relation returns &lt;code&gt;null&lt;/code&gt; when the content does not exist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$book&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// null when the book has no content yet&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Deleting a book
&lt;/h3&gt;

&lt;p&gt;The foreign key uses &lt;code&gt;ON DELETE CASCADE&lt;/code&gt;. When we delete a book, the database also deletes its content.&lt;/p&gt;

&lt;p&gt;This matches the domain: the content belongs to the book and has no purpose without it. The database prevents a &lt;code&gt;book_contents&lt;/code&gt; row from existing without a valid book.&lt;/p&gt;

&lt;h3&gt;
  
  
  Limitation
&lt;/h3&gt;

&lt;p&gt;This design is a strict one-to-one relationship. It does not support several content rows for one book. It also does not support sharing one content row between several books.&lt;/p&gt;

&lt;p&gt;For the example in Part I, these limits are useful because each content row belongs to exactly one book. If the requirements change, however, we may need a different structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Option B: Put the foreign key in the books table
&lt;/h2&gt;

&lt;p&gt;We can reverse the relationship and let &lt;code&gt;books&lt;/code&gt; reference &lt;code&gt;book_contents&lt;/code&gt;:&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="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;book_contents&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;      &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="no"&gt;AUTO_INCREMENT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;resume&lt;/span&gt;  &lt;span class="kt"&gt;TEXT&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="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;          &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="no"&gt;AUTO_INCREMENT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;       &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;content_id&lt;/span&gt;  &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;FOREIGN&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="nf"&gt;book_contents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;UNIQUE&lt;/code&gt; constraint is important if this must be a one-to-one relationship. Without it, several books could reference the same content row.&lt;/p&gt;

&lt;p&gt;In this design, a book depends on a content row. Because &lt;code&gt;content_id&lt;/code&gt; is &lt;code&gt;NOT NULL&lt;/code&gt;, we must create the content first and then create the book:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BookContent&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'resume'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$resumeText&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="nv"&gt;$book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'title'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Dune'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'content_id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$content&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every place that creates a book must follow this order. This includes API endpoints, importers, admin pages, tests, and database seeders.&lt;/p&gt;

&lt;h3&gt;
  
  
  Optional content
&lt;/h3&gt;

&lt;p&gt;If a book can exist without content, &lt;code&gt;content_id&lt;/code&gt; must be nullable:&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="n"&gt;content_id&lt;/span&gt; &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Queries must then allow for books with no content, usually with a &lt;code&gt;LEFT JOIN&lt;/code&gt;:&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="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resume&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;book_contents&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works, but the main table now contains a reference to an optional detail row. The book must know about the storage structure of one of its attributes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deleting a book
&lt;/h3&gt;

&lt;p&gt;When we delete a book, the content row is not deleted automatically. The foreign key points from &lt;code&gt;books&lt;/code&gt; to &lt;code&gt;book_contents&lt;/code&gt;, so a cascade in this direction cannot clean up the content after its book is removed.&lt;/p&gt;

&lt;p&gt;The application needs separate cleanup logic. If one deletion path forgets this step, unused content rows can remain in the database.&lt;/p&gt;

&lt;p&gt;This is not always a problem. Sometimes the referenced row is independent and should remain after the book is deleted. For example, a cover image may be reused by several book editions. In that case, a &lt;code&gt;books.cover_image_id&lt;/code&gt; column can be a good design.&lt;/p&gt;

&lt;p&gt;Option B makes sense when the referenced record has its own identity, can exist independently, or can be shared. It is usually less natural when the referenced row is only a private detail of one book.&lt;/p&gt;

&lt;h2&gt;
  
  
  Option C: Use a separate primary key for versioned content
&lt;/h2&gt;

&lt;p&gt;The shared primary key from Option A allows only one content row per book. That is exactly what we want when the system only stores the current content.&lt;/p&gt;

&lt;p&gt;But imagine that we need to keep every version. A book may have version 1, version 2, and version 3 of its content. In this case, &lt;code&gt;book_id&lt;/code&gt; cannot be the primary key because the same book ID must appear in several rows.&lt;/p&gt;

&lt;p&gt;We can give each content version its own primary key and keep &lt;code&gt;book_id&lt;/code&gt; as a separate foreign key:&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="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;book_contents&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;          &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="no"&gt;AUTO_INCREMENT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;book_id&lt;/span&gt;     &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&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="n"&gt;version&lt;/span&gt;     &lt;span class="kt"&gt;INT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&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="n"&gt;resume&lt;/span&gt;      &lt;span class="kt"&gt;TEXT&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="n"&gt;created_at&lt;/span&gt;  &lt;span class="kt"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="kc"&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;FOREIGN&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="nf"&gt;books&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;UNIQUE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&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;The two identifiers now have different purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;id&lt;/code&gt; identifies one specific content version.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;book_id&lt;/code&gt; identifies the book that owns that version.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;UNIQUE (book_id, version)&lt;/code&gt; constraint prevents two rows from using the same version number for the same book. Different books can still have the same version numbers.&lt;/p&gt;

&lt;p&gt;This is no longer a one-to-one relationship. It is a one-to-many relationship: one book has many content versions. However, the ownership direction stays the same as in Option A. The content versions depend on the book, and deleting the book can delete all of them through &lt;code&gt;ON DELETE CASCADE&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To load the newest version, we can order the versions from highest to lowest:&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="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;bc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;book_contents&lt;/span&gt; &lt;span class="n"&gt;bc&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;bc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;book_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;bc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another design could store a reference to the current version, but that adds more rules to keep the reference correct. If reading the newest version by its number is fast enough, the simpler design is often easier to maintain.&lt;/p&gt;

&lt;p&gt;Use this option only when version history is a real requirement. If the system needs only one current content row, Option A gives stronger one-to-one rules with a simpler schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to choose
&lt;/h2&gt;

&lt;p&gt;The main question is: &lt;strong&gt;which record can exist on its own, and which record depends on the other?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A book is still a book before its summary is written. The summary has no meaning without the book it describes. For that reason, the dependent table should normally contain the foreign key that points to the independent table.&lt;/p&gt;

&lt;p&gt;For this example, the choices are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Option A when each book has zero or one content row and the content belongs only to that book.&lt;/li&gt;
&lt;li&gt;Use Option B when the referenced content has its own identity, can exist independently, or may be shared.&lt;/li&gt;
&lt;li&gt;Use Option C when each book needs several historical versions of its content.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The shared primary key in Option A expresses an important rule: the content row is an extension of the book. A separate primary key in Option C expresses a different rule: every version is a separate row, but all versions still belong to one book.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;Vertical partitioning keeps the large text column out of common book queries in all three designs. The position of the foreign key does not change that performance benefit, but it changes the meaning of the relationship.&lt;/p&gt;

&lt;p&gt;When the content is a private detail of a book, put the foreign key in &lt;code&gt;book_contents&lt;/code&gt;. This allows the book to exist before its content, supports natural cleanup with &lt;code&gt;ON DELETE CASCADE&lt;/code&gt;, and prevents content from existing without an owner.&lt;/p&gt;

&lt;p&gt;If only one content row is allowed, make &lt;code&gt;book_id&lt;/code&gt; both the primary key and the foreign key. If the content must be versioned, give each version its own primary key and use &lt;code&gt;book_id&lt;/code&gt; as a separate foreign key.&lt;/p&gt;

&lt;p&gt;The best schema is not only the one that joins correctly. It is the one that expresses the real rules of the domain and lets the database help enforce them.&lt;/p&gt;

</description>
      <category>database</category>
      <category>architecture</category>
      <category>sql</category>
      <category>databasedesign</category>
    </item>
    <item>
      <title>When Large Text Belongs in a Separate Table</title>
      <dc:creator>Hugo do Carmo</dc:creator>
      <pubDate>Thu, 16 Jul 2026 00:02:02 +0000</pubDate>
      <link>https://dev.to/hugodcarmo/when-large-text-belongs-in-a-separate-table-5hfk</link>
      <guid>https://dev.to/hugodcarmo/when-large-text-belongs-in-a-separate-table-5hfk</guid>
      <description>&lt;h1&gt;
  
  
  The Hidden Cost of "Just One More Column": When Large Text Belongs in a Separate Table
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;This is Part I of a series about vertical partitioning and one-to-one table design.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Picture a simple &lt;code&gt;books&lt;/code&gt; table. It contains the fields you would expect: title, author, ISBN, publication year, and a &lt;code&gt;summary&lt;/code&gt; column with a few paragraphs about the book.&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="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;               &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="no"&gt;AUTO_INCREMENT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;            &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;author&lt;/span&gt;           &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;isbn&lt;/span&gt;             &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;published_year&lt;/span&gt;   &lt;span class="kt"&gt;SMALLINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&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="n"&gt;summary&lt;/span&gt;          &lt;span class="kt"&gt;TEXT&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="n"&gt;created_at&lt;/span&gt;       &lt;span class="kt"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;updated_at&lt;/span&gt;       &lt;span class="kt"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is nothing inherently wrong with this design. The summary belongs to the book, the table is easy to understand, and keeping the data together may be the best choice for many applications.&lt;/p&gt;

&lt;p&gt;A large text field does &lt;strong&gt;not&lt;/strong&gt; automatically need its own table.&lt;/p&gt;

&lt;p&gt;The problem appears when the application's access pattern changes. The summary may be required on a book details page, but not in search results, dropdowns, reports, or administrative listings. If the data-access technology loads every mapped column by default, a reasonable schema can begin producing unnecessary work.&lt;/p&gt;

&lt;h2&gt;
  
  
  The query that quietly becomes expensive
&lt;/h2&gt;

&lt;p&gt;Imagine a page that lists every book published after 2010. It only needs three fields:&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="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;published_year&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;published_year&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2010&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That query is precise. The database returns only what the page needs.&lt;/p&gt;

&lt;p&gt;However, many ORM calls that load complete entities generate something closer to this:&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="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;published_year&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2010&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now every summary is returned as well. If the result contains thousands of books, several kilobytes of unused text per row can become tens of megabytes transferred from the database and allocated inside the application.&lt;/p&gt;

&lt;p&gt;The application never reads the summaries, but it still pays the cost of fetching and materializing them.&lt;/p&gt;

&lt;p&gt;This behavior is not limited to one language or framework. Full-entity hydration is a common ORM default. Some persistence tools provide deferred or lazy scalar fields, while others make column selection a decision that must be repeated in each query.&lt;/p&gt;

&lt;p&gt;That difference in framework design can influence the database design.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does the database already handle large text efficiently?
&lt;/h2&gt;

&lt;p&gt;Usually, yes.&lt;/p&gt;

&lt;p&gt;Modern relational databases have mechanisms for handling large text and binary values without treating every byte as part of a small, fixed-width row. The exact strategy depends on the database engine, value size, and storage configuration, see &lt;a href="https://dev.mysql.com/doc/refman/8.4/en/innodb-row-format.html" rel="noopener noreferrer"&gt;MySQL InnoDB Row Formats&lt;/a&gt; and &lt;a href="https://www.postgresql.org/docs/current/storage-toast.html" rel="noopener noreferrer"&gt;PostgreSQL TOAST&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;More importantly, when a query requests only &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;title&lt;/code&gt;, the database does not need to return the &lt;code&gt;summary&lt;/code&gt; column to the application.&lt;/p&gt;

&lt;p&gt;So the main issue is not simply that the table contains text. The issue is that the application layer may continue asking for that text when it is not needed.&lt;/p&gt;

&lt;p&gt;This distinction matters. Moving every &lt;code&gt;TEXT&lt;/code&gt; field into another table would add joins, relationships, migrations, and lifecycle rules without necessarily improving anything. Vertical partitioning becomes useful only when the access pattern and the framework behavior make the original layout costly or difficult to control.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why explicit column selection may not be enough
&lt;/h2&gt;

&lt;p&gt;The direct solution is to select only the required columns:&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="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;published_year&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Most ORMs also provide a way to express this. Technically, that may solve the problem.&lt;/p&gt;

&lt;p&gt;The difficulty is consistency. Every new list page, API endpoint, export, scheduled job, or relationship query becomes another place where someone must remember to exclude the large field.&lt;/p&gt;

&lt;p&gt;That approach can work well when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the project has clear query conventions;&lt;/li&gt;
&lt;li&gt;the data-access layer centralizes projections;&lt;/li&gt;
&lt;li&gt;performance tests detect accidental full-row loading; or&lt;/li&gt;
&lt;li&gt;the ORM supports deferred fields as part of the model mapping.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It becomes less reliable when column selection is repeated throughout a large codebase and the framework provides no model-level way to declare that a field is rarely needed.&lt;/p&gt;

&lt;p&gt;In that situation, the risk is not that developers are careless. The risk is that the safer behavior is optional, while the expensive behavior is the default.&lt;/p&gt;

&lt;h2&gt;
  
  
  When a separate table becomes the safer option
&lt;/h2&gt;

&lt;p&gt;Suppose the summary has the following characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it is significantly larger than the other book attributes;&lt;/li&gt;
&lt;li&gt;it is needed only on a small number of screens;&lt;/li&gt;
&lt;li&gt;books are frequently loaded in lists or relationships;&lt;/li&gt;
&lt;li&gt;the ORM normally hydrates every mapped column; and&lt;/li&gt;
&lt;li&gt;there is no reliable project-wide mechanism for deferring the field.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These conditions make vertical partitioning a reasonable option.&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;-- Frequently accessed book data&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;               &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="no"&gt;AUTO_INCREMENT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;            &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;author&lt;/span&gt;           &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;isbn&lt;/span&gt;             &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;published_year&lt;/span&gt;   &lt;span class="kt"&gt;SMALLINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&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="n"&gt;created_at&lt;/span&gt;       &lt;span class="kt"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;updated_at&lt;/span&gt;       &lt;span class="kt"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_books_published_year&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;published_year&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="c1"&gt;-- Less frequently accessed large content&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;book_contents&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;book_id&lt;/span&gt;     &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;summary&lt;/span&gt;     &lt;span class="kt"&gt;TEXT&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="n"&gt;created_at&lt;/span&gt;  &lt;span class="kt"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;updated_at&lt;/span&gt;  &lt;span class="kt"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;fk_book_contents_book&lt;/span&gt;
        &lt;span class="k"&gt;FOREIGN&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="nf"&gt;books&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;CASCADE&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;The table split does not make the model more normalized. The original table was already valid from a normalization perspective.&lt;/p&gt;

&lt;p&gt;Instead, the split organizes the data by access pattern:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;books&lt;/code&gt; contains the attributes that are loaded frequently;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;book_contents&lt;/code&gt; contains the heavier content that is requested less often.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes accidental retrieval harder. A query against &lt;code&gt;books&lt;/code&gt; cannot return the summary because the column is no longer there.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Laravel example, but not a Laravel-only problem
&lt;/h2&gt;

&lt;p&gt;In Eloquent, the relationship could be represented like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;content&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasOne&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BookContent&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'book_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="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BookContent&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'book_contents'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$primaryKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'book_id'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$incrementing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;book&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;belongsTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'book_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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The common listing query loads only the smaller table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'published_year'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2010&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&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;The details page requests the content explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'content'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;findOrFail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&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;Laravel is only the implementation used in this example. The same architectural pressure can appear in any stack where complete entities are loaded by default and individual fields cannot be deferred clearly at the mapping level.&lt;/p&gt;

&lt;p&gt;If another ORM already provides reliable lazy or deferred scalar fields, keeping the summary in &lt;code&gt;books&lt;/code&gt; may remain the simpler and better design.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the shared primary key matters
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;book_contents&lt;/code&gt;, &lt;code&gt;book_id&lt;/code&gt; is both the primary key and the foreign key.&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="n"&gt;book_id&lt;/span&gt; &lt;span class="kt"&gt;BIGINT&lt;/span&gt; &lt;span class="no"&gt;UNSIGNED&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This guarantees that each book can have at most one matching content row. It also avoids adding an unrelated surrogate identifier to a table whose identity is entirely dependent on the book.&lt;/p&gt;

&lt;p&gt;The relationship is one-to-one because the database enforces it, not only because the application expects it.&lt;/p&gt;

&lt;p&gt;However, another design decision remains: why does &lt;code&gt;book_contents&lt;/code&gt; reference &lt;code&gt;books&lt;/code&gt;? Why not store a &lt;code&gt;content_id&lt;/code&gt; inside &lt;code&gt;books&lt;/code&gt; and reverse the foreign-key direction?&lt;/p&gt;

&lt;p&gt;Both layouts can represent a one-to-one relationship, but they differ in insert order, optionality, deletion behavior, and orphan management. That choice deserves a separate discussion.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;Keeping a large text field in its original table is often completely reasonable. It is simple, cohesive, and supported efficiently by modern databases.&lt;/p&gt;

&lt;p&gt;The design becomes questionable when the field is rarely needed, frequently fetched by accident, and difficult to defer because of the framework or ORM being used.&lt;/p&gt;

&lt;p&gt;At that point, the technology has created a constraint that the schema may need to address. Moving the field into a one-to-one companion table can turn an optional query convention into a structural guarantee.&lt;/p&gt;

&lt;p&gt;That is the real lesson: &lt;strong&gt;do not split a table merely because a column contains text. Split it when data size, access frequency, and framework behavior consistently work against the original design.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hugodcarmo/where-should-the-foreign-key-go-20id"&gt;Part II&lt;/a&gt; examines the next decision: where the foreign key should live in a one-to-one vertical partition, what each direction communicates, and which failure modes appear when the relationship is modeled incorrectly.&lt;/p&gt;

</description>
      <category>database</category>
      <category>performance</category>
      <category>architecture</category>
      <category>orm</category>
    </item>
  </channel>
</rss>
