Diffinery

homeflare/celldpublic

celld/docs/services/d1-flow.svg
111 lines · 6.8 KBRaw History
1<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 440 464" role="img" aria-labelledby="d1FlowTitle d1FlowDesc">
2 <title id="d1FlowTitle">A D1 database is one cell, so every statement crosses a node boundary</title>
3 <desc id="d1FlowDesc">Worker A runs three prepared statements against the binding DB and pays three
4round trips. Worker B sends the same three statements as one batch and pays one
5round trip. Both cross a node boundary, because celld routes every statement to
6the node that owns the cell. The guestbook database is one cell owned by node C.
7It holds one SQLite file and has one writer, so the three separate statements
8take three cell turns while the batch runs inside one BEGIN IMMEDIATE and COMMIT
9in a single turn, all or nothing. Below the cell, a read answers from the cell's
10own SQLite file and touches no bucket, while a write commits and then replicates
11to the fleet bucket as LTX, and the acknowledgement waits for that write. A
12second database is a second cell with its own owner node and its own writer, so
13more write capacity comes from more databases and not from a bigger one.</desc>
14 <style>
15 svg { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; }
16 text { font-size: 13px; fill: currentColor; }
17 tspan { fill: currentColor; }
18 .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
19 .lead { font-weight: 600; }
20 .d-ink { color: #121212; }
21 .d-soft { color: #3d3b37; }
22 .d-faint { color: #6e6a62; }
23 .d-acc { color: #10803f; }
24 .d-panel { color: #ffffff; }
25 .d-sunk { color: #f0eee8; }
26 .d-tint { color: #d6efdf; }
27 @media (prefers-color-scheme: dark) {
28 .d-ink { color: #efede7; }
29 .d-soft { color: #c9c6be; }
30 .d-faint { color: #928e85; }
31 .d-acc { color: #3fc472; }
32 .d-panel { color: #1a1a19; }
33 .d-sunk { color: #232321; }
34 .d-tint { color: #10301d; }
35 }
36 </style>
37 <defs>
38 <marker id="d1-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6"
39 markerHeight="6" orient="auto-start-reverse">
40 <path class="d-soft" fill="currentColor" d="M0 0 L10 5 L0 10 z" />
41 </marker>
42 </defs>
43
44 <!-- The same three statements, sent two ways. -->
45 <rect class="d-panel" fill="currentColor" x="6" y="8" width="196" height="68" rx="8" />
46 <rect class="d-faint" fill="none" stroke="currentColor" x="6" y="8" width="196" height="68" rx="8" />
47 <text class="d-faint" fill="currentColor" x="18" y="30">Worker · node A</text>
48 <text class="d-ink mono" fill="currentColor" x="18" y="52">prepare(…).run() ×3</text>
49 <text class="d-acc" fill="currentColor" x="18" y="70">three round trips</text>
50
51 <rect class="d-panel" fill="currentColor" x="238" y="8" width="196" height="68" rx="8" />
52 <rect class="d-faint" fill="none" stroke="currentColor" x="238" y="8" width="196" height="68" rx="8" />
53 <text class="d-faint" fill="currentColor" x="250" y="30">Worker · node B</text>
54 <text class="d-ink mono" fill="currentColor" x="250" y="52">batch([a, b, c])</text>
55 <text class="d-acc" fill="currentColor" x="250" y="70">one round trip</text>
56
57 <!-- The boundary every statement crosses. -->
58 <rect class="d-faint" fill="none" stroke="currentColor" stroke-dasharray="5 4"
59 x="6" y="90" width="428" height="40" rx="8" />
60 <text class="d-soft" fill="currentColor" x="220" y="110" text-anchor="middle">node boundary</text>
61 <text class="d-faint" fill="currentColor" x="220" y="126" text-anchor="middle">celld routes each call to the owner</text>
62
63 <g class="d-soft" fill="none" stroke="currentColor" stroke-width="1.5">
64 <path d="M30 76 V144" marker-end="url(#d1-arrow)" />
65 <path d="M60 76 V144" marker-end="url(#d1-arrow)" />
66 <path d="M90 76 V144" marker-end="url(#d1-arrow)" />
67 <path d="M396 76 V144" marker-end="url(#d1-arrow)" />
68 </g>
69
70 <!-- One database, one cell, one SQLite file, one writer. -->
71 <rect class="d-tint" fill="currentColor" x="16" y="144" width="408" height="134" rx="10" />
72 <rect class="d-acc" fill="none" stroke="currentColor" stroke-width="2" x="16" y="144" width="408" height="134" rx="10" />
73 <text class="d-ink lead" fill="currentColor" x="32" y="170">guestbook database = one cell · owner: node C</text>
74 <text class="d-soft" fill="currentColor" x="32" y="190">one SQLite file, one writer — statements never overlap</text>
75
76 <rect class="d-sunk" fill="currentColor" x="30" y="204" width="184" height="60" rx="8" />
77 <rect class="d-faint" fill="none" stroke="currentColor" x="30" y="204" width="184" height="60" rx="8" />
78 <text class="d-ink mono" fill="currentColor" x="122" y="228" text-anchor="middle">run · run · run</text>
79 <text class="d-soft" fill="currentColor" x="122" y="248" text-anchor="middle">three cell turns</text>
80
81 <rect class="d-sunk" fill="currentColor" x="226" y="204" width="184" height="60" rx="8" />
82 <rect class="d-faint" fill="none" stroke="currentColor" x="226" y="204" width="184" height="60" rx="8" />
83 <text class="d-ink mono" fill="currentColor" x="318" y="228" text-anchor="middle">BEGIN … COMMIT</text>
84 <text class="d-soft" fill="currentColor" x="318" y="248" text-anchor="middle">one turn, all or nothing</text>
85
86 <!-- A read stops at the cell; a write goes on to the bucket. -->
87 <g class="d-soft" fill="none" stroke="currentColor" stroke-width="1.5">
88 <path d="M100 278 V308" marker-end="url(#d1-arrow)" />
89 <path d="M330 278 V308" marker-end="url(#d1-arrow)" />
90 </g>
91 <text class="d-faint" fill="currentColor" x="108" y="300">read</text>
92 <text class="d-faint" fill="currentColor" x="338" y="300">write</text>
93
94 <rect class="d-sunk" fill="currentColor" x="16" y="312" width="196" height="76" rx="8" />
95 <rect class="d-faint" fill="none" stroke="currentColor" x="16" y="312" width="196" height="76" rx="8" />
96 <text class="d-ink" fill="currentColor" x="30" y="336">answered here</text>
97 <text class="d-soft" fill="currentColor" x="30" y="356">from the cell's SQLite</text>
98 <text class="d-faint" fill="currentColor" x="30" y="376">no bucket round trip</text>
99
100 <rect class="d-sunk" fill="currentColor" x="228" y="312" width="196" height="76" rx="8" />
101 <rect class="d-faint" fill="none" stroke="currentColor" x="228" y="312" width="196" height="76" rx="8" />
102 <text class="d-ink" fill="currentColor" x="242" y="336">commits, then LTX</text>
103 <text class="d-soft" fill="currentColor" x="242" y="356">to the fleet bucket</text>
104 <text class="d-faint" fill="currentColor" x="242" y="376">the ack waits for it</text>
105
106 <!-- Scale comes from more cells, not a bigger one. -->
107 <rect class="d-faint" fill="none" stroke="currentColor" stroke-dasharray="5 4"
108 x="16" y="404" width="408" height="50" rx="8" />
109 <text class="d-soft" fill="currentColor" x="32" y="426">orders database = a second cell, a second owner node</text>
110 <text class="d-faint" fill="currentColor" x="32" y="446">a second writer, so capacity comes from more databases</text>
111</svg>