<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Databases on Brian Faust</title><link>https://vacua.dev/tags/databases/</link><description>Recent content in Databases on Brian Faust</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 01 Jan 0001 00:00:00 +0000</lastBuildDate><atom:link href="https://vacua.dev/tags/databases/rss.xml" rel="self" type="application/rss+xml"/><item><title>Eager Loading Is Not a Query Shape</title><link>https://vacua.dev/eager-loading-is-not-a-query-shape/</link><pubDate>Sat, 01 Feb 2025 00:00:00 +0000</pubDate><guid>https://vacua.dev/eager-loading-is-not-a-query-shape/</guid><description>&lt;p&gt;A catalogue endpoint returns 25 names and the number of active variants behind
each one. The first implementation runs 26 queries. Adding
&lt;code&gt;with('activeVariants')&lt;/code&gt; reduces that to two.&lt;/p&gt;
&lt;p&gt;The N+1 defect is gone. The new implementation still hydrates 1,250 &lt;code&gt;Variant&lt;/code&gt;
models, including a synthetic 4 KiB metadata column, to produce 25 integers.&lt;/p&gt;
&lt;p&gt;Eager loading solved the repeated-query shape. It did not ask what the response
needed. That is the larger decision: queries, selected rows and columns,
hydrated models, serialization, and the database plan all belong to one read
path.&lt;/p&gt;</description></item><item><title>CQRS Starts When Reads Need a Different Model</title><link>https://vacua.dev/command-query-separation-vs-cqrs/</link><pubDate>Mon, 01 May 2023 00:00:00 +0000</pubDate><guid>https://vacua.dev/command-query-separation-vs-cqrs/</guid><description>&lt;p&gt;An order-details page needs customer name, payment status, shipment progress,
line totals, tax labels, and the latest support case. The write model needs to
protect payment, cancellation, and fulfilment invariants.&lt;/p&gt;
&lt;p&gt;Trying to make one Eloquent graph serve both jobs creates a familiar mess:
relationships exist for screen composition, write methods expose persistence
concerns, and every request loads a different subset of a model that is never
quite complete.&lt;/p&gt;
&lt;p&gt;That tension can justify different read and write models. It does not
automatically justify two databases, an event store, a command bus, or eventual
consistency. CQRS is the model split; the infrastructure is a separate set of
decisions.&lt;/p&gt;</description></item><item><title>A Version Column Is Not Concurrency Control</title><link>https://vacua.dev/a-version-column-is-not-concurrency-control/</link><pubDate>Sun, 01 Jan 2023 00:00:00 +0000</pubDate><guid>https://vacua.dev/a-version-column-is-not-concurrency-control/</guid><description>&lt;p&gt;A capacity pool has ten units available. Two workers load it before either one
writes:&lt;/p&gt;
&lt;figure class="code-figure"&gt;
 &lt;div class="code-block" data-copy-code&gt;
 &lt;button class="copy-code" type="button" aria-label="Copy code"&gt;copy&lt;/button&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;worker A loads: version 0, reserved 0
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;worker B loads: version 0, reserved 0
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;worker A allocates 6 to allocation-a
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;worker B allocates 6 to allocation-b&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
 &lt;/div&gt;
&lt;/figure&gt;
&lt;p&gt;Both decisions pass the aggregate&amp;rsquo;s rule. Each worker sees ten remaining
units. They cannot both belong to one ordered history: after either allocation,
only four remain.&lt;/p&gt;</description></item></channel></rss>