<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Tryo Asnafi</title><description>Tryo Asnafi writes about Postgres internals, distributed systems, CRDTs, Go performance and infrastructure.</description><link>https://asnafi.dev/</link><language>en</language><item><title>Hello, world: a counter that merges without coordination</title><link>https://asnafi.dev/blog/hello-world/</link><guid isPermaLink="true">https://asnafi.dev/blog/hello-world/</guid><description>The first post: a grow-only counter CRDT in Go and Postgres, why its merge never loses an increment, and a demo you can click through.</description><pubDate>Mon, 23 Nov 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This blog is about Postgres internals, distributed systems, CRDTs, Go performance and infrastructure. The first post is a small example from the middle of that list: a counter that two replicas can update without talking to each other, and that still adds up once they do.&lt;/p&gt;
&lt;div class=&quot;heading&quot;&gt;&lt;h2 id=&quot;why-last-writer-wins-loses-increments&quot;&gt;Why last-writer-wins loses increments&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;If each replica stores the count as one number, a merge has to pick one of the two numbers, and the increments behind the other one are gone. Last-writer-wins picks the most recent write.&lt;/p&gt;
&lt;p&gt;Say replica A counts 3 page views and replica B counts 2 while the network between them is down. When they reconnect, last-writer-wins keeps whichever number was written last, 3 or 2. The real total is 5.&lt;/p&gt;
&lt;div class=&quot;table-wrap&quot; tabindex=&quot;0&quot;&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;State per replica&lt;/th&gt;
&lt;th&gt;Merge&lt;/th&gt;
&lt;th&gt;Result after the example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Last writer wins&lt;/td&gt;
&lt;td&gt;One number&lt;/td&gt;
&lt;td&gt;Keep the newer number&lt;/td&gt;
&lt;td&gt;3 or 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sum on merge&lt;/td&gt;
&lt;td&gt;One number&lt;/td&gt;
&lt;td&gt;Add both numbers&lt;/td&gt;
&lt;td&gt;5, then 10 after a retry&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Grow-only counter (G-Counter)&lt;/td&gt;
&lt;td&gt;One count per replica&lt;/td&gt;
&lt;td&gt;Keep the larger count per replica&lt;/td&gt;
&lt;td&gt;5, however often it runs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Adding the numbers fixes the example and breaks the next one: a retried sync adds the same increments twice. The merge needs to be safe to repeat.&lt;/p&gt;
&lt;div class=&quot;heading&quot;&gt;&lt;h2 id=&quot;a-grow-only-counter-in-go&quot;&gt;A grow-only counter in Go&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;A grow-only counter stores a count for every replica, and each replica only ever increments its own. Its value is the sum of those counts.&lt;/p&gt;
&lt;div class=&quot;expressive-code&quot;&gt;&lt;figure class=&quot;frame has-title&quot;&gt;&lt;figcaption class=&quot;header&quot;&gt;&lt;span class=&quot;title&quot;&gt;gcounter.go&lt;/span&gt;&lt;/figcaption&gt;&lt;pre data-language=&quot;go&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;package&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gcounter&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;// Counter is a grow-only counter: one count per replica.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;type&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Counter&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;map&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;uint64&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;// Inc adds n to this replica&apos;s own count.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;func&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;c &lt;/span&gt;&lt;span&gt;Counter&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;Inc&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;replica&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;uint64&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;c[replica] &lt;/span&gt;&lt;span&gt;+=&lt;/span&gt;&lt;span&gt; n&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;// Value is the sum of every replica&apos;s count.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;func&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;c &lt;/span&gt;&lt;span&gt;Counter&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;Value&lt;/span&gt;&lt;span&gt;() &lt;/span&gt;&lt;span&gt;uint64&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span&gt;var&lt;/span&gt;&lt;span&gt; sum &lt;/span&gt;&lt;span&gt;uint64&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span&gt;for&lt;/span&gt;&lt;span&gt; _, n &lt;/span&gt;&lt;span&gt;:=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;range&lt;/span&gt;&lt;span&gt; c {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span&gt;sum &lt;/span&gt;&lt;span&gt;+=&lt;/span&gt;&lt;span&gt; n&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; sum&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;// Merge keeps the larger count for each replica.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;func&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Merge&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;b&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Counter&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;Counter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;out &lt;/span&gt;&lt;span&gt;:=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;make&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;Counter&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;len&lt;/span&gt;&lt;span&gt;(a))&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span&gt;for&lt;/span&gt;&lt;span&gt; id, n &lt;/span&gt;&lt;span&gt;:=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;range&lt;/span&gt;&lt;span&gt; a {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span&gt;out[id] &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; n&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span&gt;for&lt;/span&gt;&lt;span&gt; id, n &lt;/span&gt;&lt;span&gt;:=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;range&lt;/span&gt;&lt;span&gt; b {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span&gt;out[id] &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;max&lt;/span&gt;&lt;span&gt;(out[id], n)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; out&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight mark&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&quot;copy&quot;&gt;&lt;div aria-live=&quot;polite&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;
&lt;div class=&quot;heading&quot;&gt;&lt;h3 id=&quot;why-taking-the-maximum-is-safe&quot;&gt;Why taking the maximum is safe&lt;/h3&gt;&lt;/div&gt;
&lt;p&gt;The merge takes the larger count for each replica, and the maximum doesn’t care about order, grouping or repetition. In the paper’s terms the merge is commutative, associative and idempotent, which makes the counter a state-based CRDT&lt;sup&gt;&lt;a href=&quot;https://asnafi.dev/blog/hello-world/#user-content-fn-crdt&quot; id=&quot;user-content-fnref-crdt&quot; data-footnote-ref=&quot;true&quot; aria-describedby=&quot;footnote-label&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;. Replicas can sync in any order, any number of times, and still end up equal.&lt;/p&gt;
&lt;p&gt;Those three laws are cheap to test:&lt;/p&gt;
&lt;div class=&quot;expressive-code&quot;&gt;&lt;figure class=&quot;frame has-title&quot;&gt;&lt;figcaption class=&quot;header&quot;&gt;&lt;span class=&quot;title&quot;&gt;gcounter_test.go&lt;/span&gt;&lt;/figcaption&gt;&lt;pre data-language=&quot;go&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;func&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;TestMerge&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;testing&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;T&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;a &lt;/span&gt;&lt;span&gt;:=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Counter&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;&quot;eu&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;3&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&quot;us&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;b &lt;/span&gt;&lt;span&gt;:=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Counter&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;&quot;eu&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&quot;us&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;4&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;c &lt;/span&gt;&lt;span&gt;:=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Counter&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;&quot;ap&quot;&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;t.&lt;/span&gt;&lt;span&gt;Run&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&quot;commutative&quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;func&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;testing&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;T&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;    &lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;!&lt;/span&gt;&lt;span&gt;maps.&lt;/span&gt;&lt;span&gt;Equal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;Merge&lt;/span&gt;&lt;span&gt;(a, b), &lt;/span&gt;&lt;span&gt;Merge&lt;/span&gt;&lt;span&gt;(b, a)) {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span&gt;t.&lt;/span&gt;&lt;span&gt;Fatal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&quot;merge(a, b) != merge(b, a)&quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;})&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;t.&lt;/span&gt;&lt;span&gt;Run&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&quot;associative&quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;func&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;testing&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;T&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;    &lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;!&lt;/span&gt;&lt;span&gt;maps.&lt;/span&gt;&lt;span&gt;Equal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;Merge&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;Merge&lt;/span&gt;&lt;span&gt;(a, b), c), &lt;/span&gt;&lt;span&gt;Merge&lt;/span&gt;&lt;span&gt;(a, &lt;/span&gt;&lt;span&gt;Merge&lt;/span&gt;&lt;span&gt;(b, c))) {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span&gt;t.&lt;/span&gt;&lt;span&gt;Fatal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&quot;grouping changed the result&quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;})&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;t.&lt;/span&gt;&lt;span&gt;Run&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&quot;idempotent&quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;func&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;testing&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;T&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;    &lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;!&lt;/span&gt;&lt;span&gt;maps.&lt;/span&gt;&lt;span&gt;Equal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;Merge&lt;/span&gt;&lt;span&gt;(a, a), a) {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span&gt;t.&lt;/span&gt;&lt;span&gt;Fatal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&quot;merging with itself changed the counter&quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;})&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;t.&lt;/span&gt;&lt;span&gt;Run&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&quot;keeps every increment&quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;func&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;testing&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;T&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;    &lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt; got &lt;/span&gt;&lt;span&gt;:=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Merge&lt;/span&gt;&lt;span&gt;(a, b).&lt;/span&gt;&lt;span&gt;Value&lt;/span&gt;&lt;span&gt;(); got &lt;/span&gt;&lt;span&gt;!=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;7&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span&gt;t.&lt;/span&gt;&lt;span&gt;Fatalf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&quot;value = &lt;/span&gt;&lt;span&gt;%d&lt;/span&gt;&lt;span&gt;, want 7&quot;&lt;/span&gt;&lt;span&gt;, got)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;})&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&quot;copy&quot;&gt;&lt;div aria-live=&quot;polite&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;
&lt;div class=&quot;expressive-code&quot;&gt;&lt;figure class=&quot;frame is-terminal&quot;&gt;&lt;figcaption class=&quot;header&quot;&gt;&lt;span class=&quot;title&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sr-only&quot;&gt;Terminal window&lt;/span&gt;&lt;/figcaption&gt;&lt;pre data-language=&quot;sh&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;go&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;test&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;-v&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;./...&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&quot;copy&quot;&gt;&lt;div aria-live=&quot;polite&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;
&lt;figure&gt;&lt;picture&gt;&lt;source srcset=&quot;https://asnafi.dev/_astro/go-test.Bqe9xHI0_1jiDvF.avif 640w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_27EDEe.avif 750w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_Z1dK15Y.avif 828w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_rUAvL.avif 1080w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_ZRrjbM.avif 1200w&quot; type=&quot;image/avif&quot;&gt;&lt;source srcset=&quot;https://asnafi.dev/_astro/go-test.Bqe9xHI0_2wPiTR.webp 640w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_Z1IYOKv.webp 750w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_ZdlGM.webp 828w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_Z2l41IB.webp 1080w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_1oKcmL.webp 1200w&quot; type=&quot;image/webp&quot;&gt;&lt;img src=&quot;https://asnafi.dev/_astro/go-test.Bqe9xHI0_ZoYCHM.png&quot; srcset=&quot;https://asnafi.dev/_astro/go-test.Bqe9xHI0_ZsPEXS.png 640w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_kvk9F.png 750w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_24hNdo.png 828w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_UngYL.png 1080w, https://asnafi.dev/_astro/go-test.Bqe9xHI0_ZoYCHM.png 1200w&quot; alt=&quot;Output of go test -v: TestMerge and its four subtests, commutative, associative, idempotent and keeps every increment, all pass.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1200px) 1200px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-fit=&quot;cover&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1200&quot; height=&quot;680&quot;&gt;&lt;/picture&gt;&lt;figcaption&gt;All four subtests pass on Go 1.24.&lt;/figcaption&gt;&lt;/figure&gt;
&lt;div class=&quot;callout tip&quot; role=&quot;note&quot; data-astro-cid-q2ml7llr=&quot;&quot;&gt;&lt;p class=&quot;label&quot; data-astro-cid-q2ml7llr=&quot;&quot;&gt;Tip&lt;/p&gt;&lt;div class=&quot;body&quot; data-astro-cid-q2ml7llr=&quot;&quot;&gt;&lt;p&gt;A grow-only counter can’t go down. For a counter that also decrements, keep
two of them, one for increments and one for decrements, and subtract. That
pair is called a PN-Counter.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;heading&quot;&gt;&lt;h2 id=&quot;storing-the-counter-in-postgres&quot;&gt;Storing the counter in Postgres&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;The same merge works as an upsert: one row per counter and replica, and a conflict keeps the larger count. The value is the sum of the rows.&lt;/p&gt;
&lt;div class=&quot;expressive-code&quot;&gt;&lt;figure class=&quot;frame has-title&quot;&gt;&lt;figcaption class=&quot;header&quot;&gt;&lt;span class=&quot;title&quot;&gt;schema.sql&lt;/span&gt;&lt;/figcaption&gt;&lt;pre data-language=&quot;sql&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;CREATE&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;TABLE&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;counter_replicas&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;counter_id &lt;/span&gt;&lt;span&gt;text&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span&gt;NOT NULL&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;replica_id &lt;/span&gt;&lt;span&gt;text&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span&gt;NOT NULL&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;count      &lt;/span&gt;&lt;span&gt;bigint&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;NOT NULL&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;CHECK&lt;/span&gt;&lt;span&gt; (count &lt;/span&gt;&lt;span&gt;&amp;gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span&gt;PRIMARY KEY&lt;/span&gt;&lt;span&gt; (counter_id, replica_id)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;sum&lt;/span&gt;&lt;span&gt;(count) &lt;/span&gt;&lt;span&gt;AS&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;value&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt; counter_replicas&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;WHERE&lt;/span&gt;&lt;span&gt; counter_id &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&apos;page-views&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&quot;copy&quot;&gt;&lt;div aria-live=&quot;polite&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;
&lt;p&gt;Moving from last-writer-wins to the counter is a one-line change in the merge query:&lt;/p&gt;
&lt;div class=&quot;expressive-code&quot;&gt;&lt;figure class=&quot;frame has-title&quot;&gt;&lt;figcaption class=&quot;header&quot;&gt;&lt;span class=&quot;title&quot;&gt;merge.sql&lt;/span&gt;&lt;/figcaption&gt;&lt;pre data-language=&quot;sql&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;INSERT INTO&lt;/span&gt;&lt;span&gt; counter_replicas (counter_id, replica_id, count)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;VALUES&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;&apos;page-views&apos;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&apos;eu-1&apos;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;42&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;ON&lt;/span&gt;&lt;span&gt; CONFLICT (counter_id, replica_id)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span&gt;DO &lt;/span&gt;&lt;span&gt;UPDATE&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;SET&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight del&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;count &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;EXCLUDED&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;count&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;ec-line highlight ins&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;span class=&quot;indent&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span&gt;count &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;GREATEST&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;counter_replicas&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;count&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;EXCLUDED&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;count&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&quot;copy&quot;&gt;&lt;div aria-live=&quot;polite&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;
&lt;div class=&quot;callout warning&quot; role=&quot;note&quot; data-astro-cid-q2ml7llr=&quot;&quot;&gt;&lt;p class=&quot;label&quot; data-astro-cid-q2ml7llr=&quot;&quot;&gt;Warning&lt;/p&gt;&lt;div class=&quot;body&quot; data-astro-cid-q2ml7llr=&quot;&quot;&gt;&lt;p&gt;The upsert is only a merge if every writer sends its replica’s full count.
Sending a delta, such as “add 1”, turns it back into sum on merge, and retries
count twice. See &lt;a href=&quot;https://www.postgresql.org/docs/current/sql-insert.html&quot; rel=&quot;noopener&quot;&gt;&lt;code&gt;INSERT ... ON   CONFLICT&lt;/code&gt;&lt;/a&gt; for how
the conflict target is matched.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;heading&quot;&gt;&lt;h2 id=&quot;try-it&quot;&gt;Try it&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;Add on either replica, then merge. The counter keeps every increment; the plain number keeps only the last replica that wrote.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://asnafi.dev/blog/hello-world/&quot;&gt;Open the post to try the interactive example.&lt;/a&gt;&lt;/p&gt;
&lt;section data-footnotes=&quot;true&quot; class=&quot;footnotes&quot;&gt;&lt;h2 class=&quot;sr-only&quot; id=&quot;footnote-label&quot;&gt;Footnotes&lt;/h2&gt;
&lt;ol&gt;
&lt;li id=&quot;user-content-fn-crdt&quot;&gt;
&lt;p&gt;Marc Shapiro, Nuno Preguiça, Carlos Baquero and Marek Zawirski, “Conflict-free Replicated Data Types”, SSS 2011. The &lt;a href=&quot;https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type&quot; rel=&quot;noopener&quot;&gt;Wikipedia article&lt;/a&gt; is a good overview of the other types. &lt;a href=&quot;https://asnafi.dev/blog/hello-world/#user-content-fnref-crdt&quot; data-footnote-backref=&quot;&quot; aria-label=&quot;Back to reference 1&quot; class=&quot;data-footnote-backref&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;</content:encoded><category>crdt</category><category>distributed-systems</category><category>go</category><category>postgres</category></item></channel></rss>