<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Speechwave - Tag - Tracy Atteberry</title><link>https://tracyatteberry.com/tags/speechwave/</link><description>Speechwave - Tag - Tracy Atteberry</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><managingEditor>tracy@magicbydesign.com (Tracy Atteberry)</managingEditor><webMaster>tracy@magicbydesign.com (Tracy Atteberry)</webMaster><lastBuildDate>Thu, 19 Nov 2026 00:00:00 +0000</lastBuildDate><image><url>https://tracyatteberry.com/images/feed-icon.jpg</url><title>Speechwave - Tag - Tracy Atteberry</title><link>https://tracyatteberry.com/tags/speechwave/</link></image><atom:link href="https://tracyatteberry.com/tags/speechwave/" rel="self" type="application/rss+xml"/><item><title>What batching did for Speechwave's reaction limit</title><link>https://tracyatteberry.com/posts/sw_reaction_batching/</link><pubDate>Thu, 19 Nov 2026 00:00:00 +0000</pubDate><author>Tracy Atteberry</author><guid>https://tracyatteberry.com/posts/sw_reaction_batching/</guid><description><![CDATA[<div class="featured-image">
                <img src="https://tracyatteberry.com/posts/sw_reaction_batching/live_concert.jpg" referrerpolicy="no-referrer">
            </div><h1 id="what-batching-did-for-speechwaves-reaction-limit">What batching did for Speechwave&rsquo;s reaction limit</h1>
<p>In <a href="https://www.tracyatteberry.com/posts/sw_performance/" target="_blank" rel="noopener noreffer ">a previous post</a> I
measured how many emoji reactions <a href="https://speechwave.live" target="_blank" rel="noopener noreffer ">Speechwave</a> can
handle at once. The short version: every reaction is pushed to every audience
phone, so the work grows with the square of the room, and one core topped out
at about 35,000 of those pushes per second. Past that, a database insert would
time out inside someone&rsquo;s page, the page would crash, and their phone would
have to reconnect.</p>
<p>I ended that post with a list of fix ideas. I&rsquo;ve now made two of them, and this
post covers what I changed, what the numbers did, and a few things that got in
my way.</p>
<h2 id="what-i-did-and-didnt-do">What I did and didn&rsquo;t do</h2>
<p>The list was to batch the pushes to audience phones, to batch the database
writes, and to catch an insert failure so one timeout doesn&rsquo;t take a page down.</p>
<p>I did the first and third. I skipped batching the db writes. SQLite managed
about 7,500 inserts per second in my tests, and nothing I measured pointed at
the writes as the main problem. Batching them would add moving parts and change when
each reaction gets its timestamp, so I&rsquo;d rather wait until the numbers call for it.</p>
<h2 id="batching-the-pushes">Batching the pushes</h2>
<p>Here is how an audience page used to receive a reaction:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-elixir">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="kd">def</span> <span class="n">handle_info</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">      <span class="p">%</span><span class="nc">Phoenix.Socket.Broadcast</span><span class="p">{</span><span class="ss">event</span><span class="p">:</span> <span class="s2">&#34;new_reaction&#34;</span><span class="p">,</span> <span class="ss">payload</span><span class="p">:</span> <span class="p">%{</span><span class="ss">emoji</span><span class="p">:</span> <span class="n">emoji</span><span class="p">}},</span>
</span></span><span class="line"><span class="cl">      <span class="n">socket</span>
</span></span><span class="line"><span class="cl">    <span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="ss">:noreply</span><span class="p">,</span> <span class="n">push_event</span><span class="p">(</span><span class="n">socket</span><span class="p">,</span> <span class="s2">&#34;new_reaction&#34;</span><span class="p">,</span> <span class="p">%{</span><span class="ss">emoji</span><span class="p">:</span> <span class="n">emoji</span><span class="p">})}</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span></span></span></code></pre></div></div>
<p>One message per reaction, per page. Now a single GenServer collects the taps,
and a timer fires every 250 milliseconds. Each tick sends one message per talk,
holding everything collected since the last tick:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-elixir">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="kd">defp</span> <span class="n">send_batches</span><span class="p">(%{</span><span class="ss">pending</span><span class="p">:</span> <span class="n">pending</span><span class="p">,</span> <span class="ss">max_batch</span><span class="p">:</span> <span class="n">max_batch</span><span class="p">}</span> <span class="o">=</span> <span class="n">state</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="k">for</span> <span class="p">{</span><span class="n">slug</span><span class="p">,</span> <span class="n">newest_first</span><span class="p">}</span> <span class="o">&lt;-</span> <span class="n">pending</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">    <span class="n">emojis</span> <span class="o">=</span> <span class="n">newest_first</span> <span class="o">|&gt;</span> <span class="nc">Enum</span><span class="o">.</span><span class="n">reverse</span><span class="p">()</span> <span class="o">|&gt;</span> <span class="n">cap</span><span class="p">(</span><span class="n">max_batch</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="nc">SpeechwaveWeb.Endpoint</span><span class="o">.</span><span class="n">broadcast</span><span class="p">(</span><span class="s2">&#34;audience:</span><span class="si">#{</span><span class="n">slug</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">,</span> <span class="s2">&#34;reactions_batch&#34;</span><span class="p">,</span> <span class="p">%{</span><span class="ss">emojis</span><span class="p">:</span> <span class="n">emojis</span><span class="p">})</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="p">%{</span><span class="n">state</span> <span class="o">|</span> <span class="ss">pending</span><span class="p">:</span> <span class="p">%{}}</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span></span></span></code></pre></div></div>
<p>A page now receives about four messages a second, whether the room is quiet or
going wild. If more than 50 emoji pile up in one tick, I send a random sample of
50, since nobody can read more than that floating up a phone anyway. The
JavaScript on the page spreads each batch across the next 250 milliseconds with
a random animation delay, so it looks like a stream and not a burst.</p>
<p>We couldn&rsquo;t just batch in place and have the pages ignore the old per-reaction
message. That doesn&rsquo;t work, because Phoenix delivers a broadcast to every
process subscribed to the topic, and the delivery itself is the cost. A page
that ignores the message has still paid to receive it. So audience pages now
subscribe to their own topic, and the Chrome extension keeps getting one
message per tap on the old one. As a bonus, the extension needed no update.</p>
<p>The theoretical price is that the person tapping sees their own emoji up to 250
milliseconds later than before. I think that&rsquo;s probably okay.</p>
<h2 id="catching-the-insert-failure">Catching the insert failure</h2>
<p>When the database can&rsquo;t take a write in time, Ecto doesn&rsquo;t return an error. It
raises, and an unhandled exception in a LiveView takes the page down. So
recording a reaction now looks like this:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-elixir">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="kd">def</span> <span class="n">record_reaction</span><span class="p">(</span><span class="n">talk_id</span><span class="p">,</span> <span class="n">emoji</span><span class="p">,</span> <span class="n">slide_number</span><span class="p">,</span> <span class="n">client_id</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="c1"># ... find the active session and insert the reaction ...</span>
</span></span><span class="line"><span class="cl"><span class="k">rescue</span>
</span></span><span class="line"><span class="cl">  <span class="n">error</span> <span class="ow">in</span> <span class="p">[</span><span class="nc">DBConnection.ConnectionError</span><span class="p">,</span> <span class="nc">Exqlite.Error</span><span class="p">]</span> <span class="o">-&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="n">busy_error?</span><span class="p">(</span><span class="n">error</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">      <span class="nc">Logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&#34;reaction not recorded, database busy: </span><span class="si">#{</span><span class="n">first_line</span><span class="p">(</span><span class="n">error</span><span class="p">)</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">      <span class="ss">:telemetry</span><span class="o">.</span><span class="n">execute</span><span class="p">([</span><span class="ss">:speechwave</span><span class="p">,</span> <span class="ss">:reaction</span><span class="p">,</span> <span class="ss">:insert_failed</span><span class="p">],</span> <span class="p">%{</span><span class="ss">count</span><span class="p">:</span> <span class="mi">1</span><span class="p">},</span> <span class="p">%{})</span>
</span></span><span class="line"><span class="cl">      <span class="p">{</span><span class="ss">:error</span><span class="p">,</span> <span class="ss">:db_busy</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">else</span>
</span></span><span class="line"><span class="cl">      <span class="n">reraise</span> <span class="n">error</span><span class="p">,</span> <span class="n">__STACKTRACE__</span>
</span></span><span class="line"><span class="cl">    <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span></span></span></code></pre></div></div>
<p>The reaction is lost from the speaker&rsquo;s analytics in that case, which is why it
gets logged and counted. But the audience still sees the emoji, and nobody&rsquo;s
page crashes.</p>
<p>The first version only rescued the pool timeout, because that was the failure
I&rsquo;d seen. Then I ran the production image and checked both ways the database
can say no. Holding every pooled connection did what I expected. But SQLite
only allows one writer at a time, and when I held its write lock with a
connection free, the insert raised <code>Exqlite.Error &quot;Database busy&quot;</code> after about
two seconds, and the rescue missed it. Now it catches both. Anything else still
raises, because anything else is a real bug.</p>
<h2 id="results">Results</h2>
<p>I reran the old and new builds on the same day, on the same machine, with the
same limits as before: one pinned core, 512 MB, a database pool of 2.</p>
<table>
	<thead>
			<tr>
					<th>People</th>
					<th>Reactions/s</th>
					<th>Build</th>
					<th>CPU</th>
					<th>Delivered</th>
					<th>Delay (median / p95)</th>
					<th>Page crashes</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>400</td>
					<td>100</td>
					<td>before</td>
					<td>99%</td>
					<td>100%</td>
					<td>38 / 205 ms</td>
					<td>0</td>
			</tr>
			<tr>
					<td>400</td>
					<td>100</td>
					<td>after</td>
					<td>27%</td>
					<td>100%</td>
					<td>3 / 25 ms</td>
					<td>0</td>
			</tr>
			<tr>
					<td>400</td>
					<td>125</td>
					<td>before</td>
					<td>86%</td>
					<td>77%</td>
					<td>29 / 135 ms</td>
					<td>96</td>
			</tr>
			<tr>
					<td>400</td>
					<td>125</td>
					<td>after</td>
					<td>32%</td>
					<td>100%</td>
					<td>3 / 23 ms</td>
					<td>0</td>
			</tr>
			<tr>
					<td>800</td>
					<td>45</td>
					<td>before</td>
					<td>87%</td>
					<td>100%</td>
					<td>37 / 173 ms</td>
					<td>0</td>
			</tr>
			<tr>
					<td>800</td>
					<td>45</td>
					<td>after</td>
					<td>28%</td>
					<td>100%</td>
					<td>5 / 40 ms</td>
					<td>0</td>
			</tr>
			<tr>
					<td>800</td>
					<td>60</td>
					<td>before</td>
					<td>92%</td>
					<td>81%</td>
					<td>709 / 1,312 ms</td>
					<td>171</td>
			</tr>
			<tr>
					<td>800</td>
					<td>60</td>
					<td>after</td>
					<td>30%</td>
					<td>100%</td>
					<td>3 / 19 ms</td>
					<td>0</td>
			</tr>
			<tr>
					<td>1,200</td>
					<td>40</td>
					<td>before</td>
					<td>100%</td>
					<td>83%</td>
					<td>921 ms (2 probes)</td>
					<td>213</td>
			</tr>
			<tr>
					<td>1,200</td>
					<td>40</td>
					<td>after</td>
					<td>30%</td>
					<td>100%</td>
					<td>4 / 40 ms</td>
					<td>0</td>
			</tr>
	</tbody>
</table>
<p>At the same load, CPU fell to about a third, every reaction arrived, and the
crashes went away at every step that used to produce them. The 1,200-person row
is everyone tapping once every 30 seconds, which is closer to a real audience.</p>
<p>A few caveats. These are single 60-second runs, and each has only 11 timing
probes, so treat the delays as rough. &ldquo;Delay&rdquo; is measured at the extension-style
listener, which still gets one message per tap. It says nothing about audience
pages, which now wait up to 250 milliseconds longer by design. And the old
numbers here differ a little from the table in the last post, because I
remeasured them instead of copying them.</p>
<h2 id="limitations">Limitations</h2>
<p>I didn&rsquo;t find the new limit. I only reran the old steps, and the new build
didn&rsquo;t break at any of them. The old rule of thumb (keep total reactions per
second under 35,000 divided by the number of people) no longer describes this
build, because each page&rsquo;s message rate is now fixed at about four a second.</p>
<p>Memory is probably next. The 1,200-person run used about 417 MB of the 512 MB
available, and the last post&rsquo;s 3,200-person run was killed for running out of
memory. If you have a few thousand people in a room tapping at once, that&rsquo;s
where we&rsquo;d look first. We should also measure the extension side, since the
speaker&rsquo;s laptop still gets every reaction individually.</p>
<p>For talks of a few hundred people, the answer to &ldquo;how many reactions can the
audience send at once?&rdquo; was already &ldquo;plenty&rdquo;. Now it&rsquo;s &ldquo;plenty, with room to
spare.&rdquo;</p>
]]></description></item><item><title>How many reactions per second can Speechwave handle?</title><link>https://tracyatteberry.com/posts/sw_performance/</link><pubDate>Tue, 10 Nov 2026 00:00:00 +0000</pubDate><author>Tracy Atteberry</author><guid>https://tracyatteberry.com/posts/sw_performance/</guid><description><![CDATA[<div class="featured-image">
                <img src="https://tracyatteberry.com/posts/sw_performance/concert.jpg" referrerpolicy="no-referrer">
            </div><h1 id="how-many-reactions-per-second-can-speechwave-handle">How many reactions per second can Speechwave handle?</h1>
<p>A user recently sent us this question:</p>
<blockquote>
<p>How many reactions can the audience send at once before the emoji display slows down or drops some of them?</p>
</blockquote>
<p>It&rsquo;s a fair question to ask before you put an app in front of a few hundred
people at a conference. We haven&rsquo;t had a reported issue yet, but I realized I
had never actually measured it. So I did, and here are the results.</p>
<p>If you haven&rsquo;t seen it, <a href="https://speechwave.live" target="_blank" rel="noopener noreffer ">Speechwave</a> is a live emoji
reaction app for talks. The audience taps emoji on their phones, and a Chrome
extension floats them over the speaker&rsquo;s slides. The speaker gets analytics afterward.</p>
<h2 id="great-expectations">Great expectations</h2>
<p>I already knew from developing the code that each audience member is limited to
one reaction every 3 seconds. So the most any room can send is the number of
people divided by 3, per second. A 300-person room tops out at 100 reactions
per second, and only if everyone taps the instant their button comes back,
<em>and</em> that&rsquo;s if you get 100% room participation.</p>
<p>That gives us our theoretical maximum, but tells us nothing about what the
server does at 100 reactions per second.</p>
<h2 id="what-about-sqlite">What about SQLite?</h2>
<p>I next guessed that SQLite could be a weak spot. Every accepted reaction is
saved to the database, and SQLite has a reputation for being a single-writer
database. However, it turns out SQLite can write far more than a few hundred
rows a second.</p>
<p>Measuring it inside the same container used for the rest of the test, it did
about 7,500 inserts per second. It didn&rsquo;t seem like the database was going to
be out limiting factor.</p>
<h2 id="testing-methods">Testing methods</h2>
<p>Wanting the test to look like production, I built the production Docker image
and ran it locally with the same limits as my Fly machine: one CPU, 512 MB of
memory, and a database pool of 2. Then I wrote a small Node script that
simulates an audience. Each fake person loads the talk page, joins the LiveView
over a websocket, and taps on a timer. A second connection plays the Chrome
extension and times how long a reaction takes to arrive.</p>
<p>There were two gotchas.</p>
<p>First, Docker&rsquo;s <code>--cpus=1</code> limits how much CPU time a container gets, but the
Erlang VM still looked at my laptop and started eight schedulers. On Fly it
would see one. When I pinned the container to a single core, the numbers got a
worse, but a lot more realistic.</p>
<p>Second, <strong>the load generator was the bottleneck</strong>. Every reaction is sent to every
audience phone, so with 800 fake people one Node process had to read about 200,000
messages per second. It couldn&rsquo;t, and that backed things up on the server in a way
real phones wouldn&rsquo;t. I split the generator across several processes and made it
count messages without parsing them.</p>
<h2 id="results">Results</h2>
<p>I held the audience at a fixed size and raised the total number of reactions per
second until something gave.</p>
<table>
	<thead>
			<tr>
					<th>People</th>
					<th>Reactions/s</th>
					<th>CPU</th>
					<th>Delivered</th>
					<th>Delay (median / p95)</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>400</td>
					<td>60</td>
					<td>68%</td>
					<td>100%</td>
					<td>4 / 18 ms</td>
			</tr>
			<tr>
					<td>400</td>
					<td>100</td>
					<td>99%</td>
					<td>100%</td>
					<td>60 / 116 ms</td>
			</tr>
			<tr>
					<td>400</td>
					<td>125</td>
					<td>86%</td>
					<td>84%</td>
					<td>24 / 430 ms</td>
			</tr>
			<tr>
					<td>800</td>
					<td>25</td>
					<td>63%</td>
					<td>100%</td>
					<td>3 / 88 ms</td>
			</tr>
			<tr>
					<td>800</td>
					<td>45</td>
					<td>100%</td>
					<td>100%</td>
					<td>76 / 251 ms</td>
			</tr>
			<tr>
					<td>800</td>
					<td>60</td>
					<td>100%</td>
					<td>82%</td>
					<td>43 / 1,495 ms</td>
			</tr>
	</tbody>
</table>
<p>Of course, the answer depends on how many people are in the room.
With 400 people, things slow down at about 100 reactions per second and start
dropping soon after. With 800 people, the same thing happens at about 45.</p>
<h2 id="showing-everybody-everything">Showing everybody everything</h2>
<p>Here&rsquo;s the part I hadn&rsquo;t initially thought about. The audience page also shows
the floating emoji, so that people can see their reaction appear. That means
every reaction is pushed to every connected phone, not only to the speaker&rsquo;s
laptop.</p>
<p>Here&rsquo;s the handler from the audience LiveView:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-elixir">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="kd">def</span> <span class="n">handle_info</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">      <span class="p">%</span><span class="nc">Phoenix.Socket.Broadcast</span><span class="p">{</span><span class="ss">event</span><span class="p">:</span> <span class="s2">&#34;new_reaction&#34;</span><span class="p">,</span> <span class="ss">payload</span><span class="p">:</span> <span class="p">%{</span><span class="ss">emoji</span><span class="p">:</span> <span class="n">emoji</span><span class="p">}},</span>
</span></span><span class="line"><span class="cl">      <span class="n">socket</span>
</span></span><span class="line"><span class="cl">    <span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="ss">:noreply</span><span class="p">,</span> <span class="n">push_event</span><span class="p">(</span><span class="n">socket</span><span class="p">,</span> <span class="s2">&#34;new_reaction&#34;</span><span class="p">,</span> <span class="p">%{</span><span class="ss">emoji</span><span class="p">:</span> <span class="n">emoji</span><span class="p">})}</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span></span></span></code></pre></div></div>
<p>Every audience member runs that for every reaction. So the work per second is the
number of people times the number of reactions per second, which grows with the
square of the room. In my runs one core topped out at about 35,000 to 40,000 of
those pushes per second, and both of my break points were right there:</p>
<ul>
<li>400 people × 100 reactions/s = 40,000</li>
<li>800 people × 45 reactions/s = 36,000</li>
</ul>
<p>That gives us a rule of thumb: <strong>total reactions per second should stay under about
35,000 divided by the number of people</strong>. A room of 1,000 can handle about 35 reactions
per second. A room of 200 can handle about 175, though it can&rsquo;t reach that, because the
3-second limit caps it at about 67.</p>
<p>Real audiences don&rsquo;t tap constantly. If each person reacts about once every 30
seconds, 800 people send 27 reactions per second, and that ran fine at 55% CPU.
Raise it to 1,200 people at the same pace and the core saturates. Obviously, we
could handle higher loads if we assume less than 100% participation.</p>
<h2 id="what-failure-mode-looks-like">What failure mode looks like</h2>
<p>We want things to degrade gracefully. When the core is saturated, the database insert
inside someone&rsquo;s LiveView waits too long for a pool connection and raises. That
crashes the process, so the reaction is lost, and the phone has to reconnect.
While it&rsquo;s not ideal, the audience is unlikely to notice a few lost reactions.
However&hellip;</p>
<p>Memory was the other ceiling. Each connected person costs about 0.23 MB on top of a
baseline around 160 MB. A 3,200-person run was killed for running out of memory.
That&rsquo;s not something we&rsquo;ve seen in production yet, but it wouldn&rsquo;t be great.</p>
<h2 id="how-we-can-make-it-even-better">How we can make it even better</h2>
<p>The obvious fixes are to batch the pushes to audience phones (one message every
quarter second instead of one per reaction), to batch the database writes, and
to catch an insert failure so one timeout doesn&rsquo;t take a page down with it. The
first one attacks the primary issue. Of course, if we need to, we can always
scale our servers at Fly as well.</p>
<p>Caveats: These were single runs, so the edges are fuzzy: one 800-person run
lost 5% of its reactions at a rate where a harder run lost none, so there&rsquo;s
some variance here. Fly&rsquo;s shared CPU can be throttled harder than a pinned core
on my laptop, so the real limits may be lower. Also, I only measured the server.
Whether the emoji on the speaker&rsquo;s screen keep up at these rates is a separate
test. For <em>really</em> large talks we may need to throttle/summarize the reaction
stream going to the speaker&rsquo;s broswer extension.</p>
<h2 id="so-in-summary">So in summary&hellip;</h2>
<p>For a typical talk with a few hundred participants, life should be good. For a
thousand active particpants (congratulations!), reactions might start to drop
above roughly 35 reactions per second across the whole audience, which is what
you&rsquo;d see if everyone tapped about once every 30 seconds and then something
exciting happened in the talk. That&rsquo;s a good problem to have, and now we know
where the edge is. Even better, we know how to push the edge out futher if we
need to.</p>
]]></description></item><item><title>Why I built Speechwave in Elixir (as a Rails developer)</title><link>https://tracyatteberry.com/posts/why-elixir/</link><pubDate>Tue, 03 Nov 2026 00:00:00 +0000</pubDate><author>Tracy Atteberry</author><guid>https://tracyatteberry.com/posts/why-elixir/</guid><description><![CDATA[<div class="featured-image">
                <img src="https://tracyatteberry.com/posts/why-elixir/swhero.png" referrerpolicy="no-referrer">
            </div><h1 id="why-i-built-speechwave-in-elixir-as-a-rails-developer">Why I built Speechwave in Elixir (as a Rails developer)</h1>
<p>I&rsquo;ve been developing with Ruby on Rails for a long time. If you had asked me to bet on
what I&rsquo;d build my next web app with, I would have bet on Rails.</p>
<p>Then I started building <a href="https://speechwave.live" target="_blank" rel="noopener noreffer ">Speechwave</a>, a live emoji reaction app
for conference talks, and I wrote it in Elixir instead</p>
<p>This isn&rsquo;t a &ldquo;Rails is dead&rdquo; post. It&rsquo;s still a great choice for lots of
things. This is about what this particular app needed, why Elixir turned out to
a great choice, and why the hosting bill is about as small as a bill can get. If you&rsquo;re an Elixir
developer, some of this may be familiar.</p>
<h2 id="what-speechwave-does">What Speechwave does</h2>
<p>Attendees scan a QR code at a talk and are sent to a page of emoji buttons. They
tap one. A Chrome extension on the speaker&rsquo;s laptop receives that reaction and
floats the emoji over the speaker&rsquo;s Google Slides in real time. After the talk,
the speaker can see which slides got which reactions.</p>
<p>Look at that from a server&rsquo;s point of view. It&rsquo;s a lot of small, short-lived,
simultaneous things:</p>
<ul>
<li>Dozens (or hundreds) of phones holding open WebSocket connections</li>
<li>Each tap needs to be rate limited, optionally saved, and fanned out to
everyone who cares</li>
<li>The speaker&rsquo;s extension holds one more long-lived connection, and it isn&rsquo;t
even a web page</li>
<li>The whole thing is quiet for days, then very busy for 45 minutes</li>
</ul>
<p>That last point will matter quite a bit when we get to the hosting
section.</p>
<h2 id="why-it-works-the-three-things-i-would-have-had-to-do-in-rails">Why it works: the three things I would have had to do in Rails</h2>
<p>I don&rsquo;t want to oversell this. Rails can do real-time. Action Cable exists,
and Rails keeps improving. But in Rails I would have been assembling
pieces. In Phoenix, the pieces come in the box and they were designed together.</p>
<h3 id="1-a-message-bus-that-doesnt-care-whos-listening">1. A message bus that doesn&rsquo;t care who&rsquo;s listening</h3>
<p>Phoenix PubSub lets any process broadcast to a topic and any other process
subscribe to it. The attendee&rsquo;s LiveView doesn&rsquo;t know the Chrome extension
exists. After the rate limit check (and saving the reaction, if a session is
recording), it just broadcasts. Here&rsquo;s the handler from <code>talk_live.ex</code>, with the
persistence code trimmed out:</p>
<div class="code-block code-line-numbers" style="counter-reset: code-block 0">
    <div class="code-header language-elixir">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="kd">def</span> <span class="n">handle_event</span><span class="p">(</span><span class="s2">&#34;react&#34;</span><span class="p">,</span> <span class="p">%{</span><span class="s2">&#34;emoji&#34;</span> <span class="o">=&gt;</span> <span class="n">emoji</span><span class="p">},</span> <span class="n">socket</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="k">if</span> <span class="nc">RateLimiter</span><span class="o">.</span><span class="n">allow?</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">assigns</span><span class="o">.</span><span class="n">session_id</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># ...save the reaction if a session is recording...</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="nc">SpeechwaveWeb.Endpoint</span><span class="o">.</span><span class="n">broadcast!</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">      <span class="s2">&#34;reactions:</span><span class="si">#{</span><span class="n">socket</span><span class="o">.</span><span class="n">assigns</span><span class="o">.</span><span class="n">talk</span><span class="o">.</span><span class="n">slug</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="s2">&#34;new_reaction&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="p">%{</span><span class="ss">emoji</span><span class="p">:</span> <span class="n">emoji</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="ss">:noreply</span><span class="p">,</span> <span class="n">socket</span><span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span></span></span></code></pre></div></div>
<p>The extension&rsquo;s channel is subscribed to the same topic, so it gets the
message. If it add a third kind of listener tomorrow, say a live dashboard,
nothing in that function changes.</p>
<h3 id="2-liveview-for-the-attendee-page">2. LiveView for the attendee page</h3>
<p>The attendee page is a LiveView, so we got WebSocket-backed interactivity without
building a single-page app and without maintaining a separate JavaScript
frontend. The UI is a function of server state, and Phoenix handles keeping the
browser in sync. For an app where nearly every interesting event is &ldquo;something
happened on the server, tell the clients,&rdquo; that model is a very good match.</p>
<h3 id="3-cheap-isolated-processes-for-everything-else">3. Cheap, isolated processes for everything else</h3>
<p>The rate limiter is a <code>GenServer</code> that owns an ETS table (an in-memory
key/value store built into the runtime). Reads don&rsquo;t queue behind the
GenServer, so a room full of people tapping at once doesn&rsquo;t turn into a
traffic jam. It&rsquo;s a few dozen lines and there is no Redis anywhere.</p>
<p>Presence, which tracks how many extensions are connected to a talk so we can
enforce plan limits, is also built in. So is the supervision tree that restarts
any piece that crashes without taking down the rest. Here&rsquo;s the top level of
the tree from <code>application.ex</code>, trimmed a bit for space:</p>
<div class="code-block code-line-numbers" style="counter-reset: code-block 0">
    <div class="code-header language-elixir">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="n">children</span> <span class="o">=</span>
</span></span><span class="line"><span class="cl">  <span class="p">[</span>
</span></span><span class="line"><span class="cl">    <span class="nc">Speechwave.Repo</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="p">{</span><span class="nc">Phoenix.PubSub</span><span class="p">,</span> <span class="ss">name</span><span class="p">:</span> <span class="nc">Speechwave.PubSub</span><span class="p">},</span>
</span></span><span class="line"><span class="cl">    <span class="nc">Speechwave.RateLimiter</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nc">Speechwave.AuthThrottle</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># ...a few more throttles and reapers...</span>
</span></span><span class="line"><span class="cl">    <span class="nc">SpeechwaveWeb.Endpoint</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nc">SpeechwaveWeb.Presence</span>
</span></span><span class="line"><span class="cl">  <span class="p">]</span> <span class="o">++</span> <span class="n">backup_children</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">opts</span> <span class="o">=</span> <span class="p">[</span><span class="ss">strategy</span><span class="p">:</span> <span class="ss">:one_for_one</span><span class="p">,</span> <span class="ss">name</span><span class="p">:</span> <span class="nc">Speechwave.Supervisor</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="nc">Supervisor</span><span class="o">.</span><span class="n">start_link</span><span class="p">(</span><span class="n">children</span><span class="p">,</span> <span class="n">opts</span><span class="p">)</span></span></span></code></pre></div></div>
<p>I wrote down what happens when each child crashes (the rate limiter loses its
cooldown state, Presence resets its count, and so on) and for this app every
answer is &ldquo;acceptable, by design.&rdquo; Thinking about failure that explicitly is
something the platform nudges you toward. In a Rails apps, I mostly find out
what a crash does when it happens.</p>
<h2 id="the-hosting-bill">The hosting bill</h2>
<p>This is the part I was the most excited about, and why I&rsquo;m writing this
post in the first place.</p>
<p>Speechwave runs on <a href="https://fly.io" target="_blank" rel="noopener noreffer ">Fly.io</a>, and here are the essential bits
configuration:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-toml">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[[</span><span class="nx">vm</span><span class="p">]]</span>
</span></span><span class="line"><span class="cl">  <span class="nx">memory</span> <span class="p">=</span> <span class="s1">&#39;512mb&#39;</span>
</span></span><span class="line"><span class="cl">  <span class="nx">cpu_kind</span> <span class="p">=</span> <span class="s1">&#39;shared&#39;</span>
</span></span><span class="line"><span class="cl">  <span class="nx">cpus</span> <span class="p">=</span> <span class="mi">1</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">[</span><span class="nx">http_service</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">  <span class="nx">auto_stop_machines</span> <span class="p">=</span> <span class="s1">&#39;suspend&#39;</span>
</span></span><span class="line"><span class="cl">  <span class="nx">auto_start_machines</span> <span class="p">=</span> <span class="kc">true</span>
</span></span><span class="line"><span class="cl">  <span class="nx">min_machines_running</span> <span class="p">=</span> <span class="mi">0</span></span></span></code></pre></div></div>
<p>That&rsquo;s one shared CPU and 512 MB of memory. When nobody is using the app, the
machine suspends. When someone scans a QR code, it wakes up.</p>
<p>Three things make that work, and Elixir is part of each of them.</p>
<p><strong>The runtime is frugal.</strong> Because the BEAM runs lightweight processes instead
of OS threads, one small machine can hold a lot of open connections. I&rsquo;ve
configured the app to allow up to 1,000 concurrent connections on that single
512 MB box. For context, my realistic target is a few conference rooms, not a
stadium.</p>
<p><strong>One process serves everything.</strong> The reaction fan-out, the LiveView pages,
the Channel for the extension, the rate limiter, the presence tracking, and the
scheduled backups all run inside a single Elixir application. I don&rsquo;t need a
separate Redis for pub/sub, a separate worker process for background jobs, or a
separate WebSocket server. Fewer moving parts means fewer things to pay for and
fewer things to keep alive.</p>
<p><strong>SQLite is enough.</strong> The first version of this app used Fly&rsquo;s managed
Postgres. I&rsquo;ve since moved to SQLite on a Fly volume, with Ecto&rsquo;s SQLite
adapter and a pool size of 2. Reactions are small writes, the data volume is
tiny, and a few talk-shaped workloads doesn&rsquo;t need a database server.</p>
<p>That does mean I own backups. A GenServer takes a snapshot every hour using
SQLite&rsquo;s <code>VACUUM INTO</code> (which gives a consistent copy of a live database,
unlike copying the file) and uploads it to an S3-compatible object storage. It&rsquo;s
about a hundred lines of Elixir, it&rsquo;s supervised like everything else, and a
failed backup logs an error instead of crashing anything. If you want the
details, the <a href="https://docs.speechwave.live/dev/explainer/db-backup.html" target="_blank" rel="noopener noreffer ">codebase explainer</a>
walks through it.</p>
<p>Put those together and the cost is tiny. Fly waives invoices under $5, and only
last month did my bill creep above that to $5.49, just a little over the
line. Usage of the S3 object store at Tigris has stayed within its free
allowances.</p>
<p>I want to be careful about what I&rsquo;m claiming. That number reflects low traffic
on a young app. I haven&rsquo;t load tested a 5,000-person keynote, and I&rsquo;m not
claiming this configuration handles one. What I can say is that the floor is
very low, and the architecture doesn&rsquo;t force me to pay for a fleet of
services before I&rsquo;ve earned a paying user.</p>
<h2 id="could-i-have-done-this-in-rails">Could I have done this in Rails?</h2>
<p>Probably, yes. Rails 8 made SQLite a first-class citizen, and Solid Cable
removes the Redis requirement for Action Cable. I&rsquo;m not going to pretend that
Rails can&rsquo;t get to a similar place. A fair comparison, though, is about how
much I had to assemble and tune to get there, and about how comfortable the
result is at idle and at peak.</p>
<p>For this specific shape of app, many long-lived connections, constant
broadcast, tiny writes, spiky traffic, Phoenix gave me the right design
without much negotiation. In Rails I would have been making deliberate choices
to approximate it.</p>
<p>I&rsquo;ll also say what I did <strong>not</strong> get for free. Rails has an enormous ecosystem
of gems that solve the boring parts of an app. In Elixir I wrote more of the
glue myself. Authentication is a good example: magic links and OAuth took more
work (Phoenix&rsquo;s generator got me started, and a library called Assent handles
the OAuth side). If this had been a plain CRUD app with admin screens, Rails
may have been faster to build, and I may have shipped it sooner.</p>
<h2 id="what-learning-elixir-was-like-for-a-ruby-developer">What learning Elixir was like for a Ruby developer</h2>
<p>Easier than I expected, honestly. The syntax is friendly to Rubyists, the
tooling (<code>mix</code>, <code>iex</code>, ExUnit) feels familiar, and the community writes really
good documentation. The adjustments that took some effort were more conceptual:</p>
<ul>
<li>Data is immutable, so you transform values instead of mutating objects.</li>
<li>Pattern matching shows up everywhere, and it replaces a surprising amount of
<code>if</code> and <code>case</code> logic.</li>
<li>You think in processes, which is a new mental model, but a pleasant one once
it clicks.</li>
</ul>
<p>If you&rsquo;ve used Ruby 3&rsquo;s <code>case/in</code>, pattern matching won&rsquo;t be a brand new idea.
You can destructure hashes and arrays, bind variables, and pin values with <code>^</code>:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-ruby">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="k">case</span> <span class="n">response</span>
</span></span><span class="line"><span class="cl"><span class="k">in</span> <span class="p">{</span><span class="ss">status</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span> <span class="ss">body</span><span class="p">:}</span>
</span></span><span class="line"><span class="cl">  <span class="n">render</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="k">in</span> <span class="p">{</span><span class="ss">status</span><span class="p">:</span> <span class="mi">404</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">  <span class="n">not_found</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span></span></span></code></pre></div></div>
<p>The difference is how deep it goes. In Ruby, pattern matching is a feature you
opt into with <code>case/in</code>, and most Ruby code still uses <code>if</code>, <code>case/when</code>, and
guard clauses. In Elixir it&rsquo;s foundational. Even <code>=</code> is a match operator, not
just assignment. Most importantly, you can match right in a function&rsquo;s
arguments, so each clause of a function handles one shape of input. Speechwave&rsquo;s
Channel has two <code>join</code> functions, for example (from <code>reaction_channel.ex</code>, with
the first one&rsquo;s body trimmed):</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-elixir">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="kd">def</span> <span class="n">join</span><span class="p">(</span><span class="s2">&#34;reactions:&#34;</span> <span class="o">&lt;&gt;</span> <span class="n">slug</span><span class="p">,</span> <span class="p">%{</span><span class="s2">&#34;api_key&#34;</span> <span class="o">=&gt;</span> <span class="n">api_key</span><span class="p">},</span> <span class="n">socket</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="c1"># ...check the talk, the user, and the plan limits...</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">def</span> <span class="n">join</span><span class="p">(</span><span class="s2">&#34;reactions:&#34;</span> <span class="o">&lt;&gt;</span> <span class="n">_slug</span><span class="p">,</span> <span class="n">_params</span><span class="p">,</span> <span class="n">_socket</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="ss">:error</span><span class="p">,</span> <span class="p">%{</span><span class="ss">reason</span><span class="p">:</span> <span class="s2">&#34;unauthorized&#34;</span><span class="p">}}</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span></span></span></code></pre></div></div>
<p>The first clause only matches when the topic starts with <code>&quot;reactions:&quot;</code> and the
params include an <code>api_key</code>. Anything else falls through to the second clause,
which rejects it. No <code>if</code> required.</p>
<p>Ruby methods have one body, so you branch inside it. Elixir functions can have
many clauses, and the branching happens before your code even runs. That&rsquo;s the
part that changed how code was structured, and it&rsquo;s why pattern matching feels
more like a way of working than a convenient syntax.</p>
<p>Here&rsquo;s an example. The Channel join for the Chrome extension is a chain of
four checks, and each failure has its own reason. This is the body of that first
<code>join</code> clause, minus a couple of setup lines inside the <code>do</code> block:</p>
<div class="code-block code-line-numbers" style="counter-reset: code-block 0">
    <div class="code-header language-elixir">
        <span class="code-title"><i class="arrow fas fa-chevron-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="n">with</span> <span class="p">{</span><span class="ss">:talk</span><span class="p">,</span> <span class="p">%</span><span class="nc">Talks.Talk</span><span class="p">{}</span> <span class="o">=</span> <span class="n">talk</span><span class="p">}</span> <span class="o">&lt;-</span> <span class="p">{</span><span class="ss">:talk</span><span class="p">,</span> <span class="nc">Talks</span><span class="o">.</span><span class="n">get_talk_by_slug</span><span class="p">(</span><span class="n">slug</span><span class="p">)},</span>
</span></span><span class="line"><span class="cl">     <span class="p">{</span><span class="ss">:user</span><span class="p">,</span> <span class="p">%</span><span class="nc">Accounts.User</span><span class="p">{}</span> <span class="o">=</span> <span class="n">user</span><span class="p">}</span> <span class="o">&lt;-</span> <span class="p">{</span><span class="ss">:user</span><span class="p">,</span> <span class="nc">Accounts</span><span class="o">.</span><span class="n">get_user_by_api_key</span><span class="p">(</span><span class="n">api_key</span><span class="p">)},</span>
</span></span><span class="line"><span class="cl">     <span class="p">{</span><span class="ss">:owner</span><span class="p">,</span> <span class="no">true</span><span class="p">}</span> <span class="o">&lt;-</span> <span class="p">{</span><span class="ss">:owner</span><span class="p">,</span> <span class="n">talk</span><span class="o">.</span><span class="n">user_id</span> <span class="o">==</span> <span class="n">user</span><span class="o">.</span><span class="n">id</span><span class="p">},</span>
</span></span><span class="line"><span class="cl">     <span class="p">{</span><span class="ss">:capacity</span><span class="p">,</span> <span class="ss">:ok</span><span class="p">}</span> <span class="o">&lt;-</span>
</span></span><span class="line"><span class="cl">       <span class="p">{</span><span class="ss">:capacity</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="nc">Plans</span><span class="o">.</span><span class="n">check</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">          <span class="ss">:max_participants</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">          <span class="n">user</span><span class="o">.</span><span class="n">plan</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">          <span class="nc">Presence</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="s2">&#34;reactions:</span><span class="si">#{</span><span class="n">slug</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">)</span> <span class="o">|&gt;</span> <span class="n">map_size</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">        <span class="p">)}</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="c1"># ...subscribe to disconnect events, schedule presence tracking...</span>
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="ss">:ok</span><span class="p">,</span> <span class="n">join_payload</span><span class="p">(</span><span class="n">user</span><span class="p">),</span> <span class="n">assign</span><span class="p">(</span><span class="n">socket</span><span class="p">,</span> <span class="ss">talk</span><span class="p">:</span> <span class="n">talk</span><span class="p">,</span> <span class="ss">user</span><span class="p">:</span> <span class="n">user</span><span class="p">)}</span>
</span></span><span class="line"><span class="cl"><span class="k">else</span>
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="ss">:talk</span><span class="p">,</span> <span class="no">nil</span><span class="p">}</span> <span class="o">-&gt;</span> <span class="p">{</span><span class="ss">:error</span><span class="p">,</span> <span class="p">%{</span><span class="ss">reason</span><span class="p">:</span> <span class="s2">&#34;not_found&#34;</span><span class="p">}}</span>
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="ss">:user</span><span class="p">,</span> <span class="no">nil</span><span class="p">}</span> <span class="o">-&gt;</span> <span class="p">{</span><span class="ss">:error</span><span class="p">,</span> <span class="p">%{</span><span class="ss">reason</span><span class="p">:</span> <span class="s2">&#34;unauthorized&#34;</span><span class="p">}}</span>
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="ss">:owner</span><span class="p">,</span> <span class="no">false</span><span class="p">}</span> <span class="o">-&gt;</span> <span class="p">{</span><span class="ss">:error</span><span class="p">,</span> <span class="p">%{</span><span class="ss">reason</span><span class="p">:</span> <span class="s2">&#34;unauthorized&#34;</span><span class="p">}}</span>
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="ss">:capacity</span><span class="p">,</span> <span class="p">{</span><span class="ss">:error</span><span class="p">,</span> <span class="ss">:limit_reached</span><span class="p">}}</span> <span class="o">-&gt;</span> <span class="p">{</span><span class="ss">:error</span><span class="p">,</span> <span class="p">%{</span><span class="ss">reason</span><span class="p">:</span> <span class="s2">&#34;capacity_reached&#34;</span><span class="p">}}</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span></span></span></code></pre></div></div>
<p>I might have written that as a pile of guard clauses in Ruby. This version
reads top to bottom as a list of requirements, and the <code>else</code> block is a
table of what goes wrong.</p>
<p>As an aid to learning I had AI help me write a <a href="https://docs.speechwave.live/dev/course.html" target="_blank" rel="noopener noreffer ">short course for Ruby
developers</a>, drawing the examples
from the Speechwave codebase. If you&rsquo;re coming from the Rails side, that&rsquo;s an
interesting place to start.</p>
<h2 id="what-id-tell-another-rails-developer">What I&rsquo;d tell another Rails developer</h2>
<p>If your app is mostly forms, tables, and background jobs, stay with Rails. You&rsquo;ll
move faster and you&rsquo;ll have more gems to lean on.</p>
<p>If your app is mostly &ldquo;lots of people connected at once, and something
happening to all of them in real time,&rdquo; look hard at Phoenix. The runtime and
the framework were built for exactly that, and you may find, as I did, that the
infrastructure shrinks down to a single small machine.</p>
<p>And if you&rsquo;re already an Elixir developer: I&rsquo;d love your feedback on the
codebase. It&rsquo;s open, it&rsquo;s about 6,800 lines of application code, and I&rsquo;m sure
there are idioms I&rsquo;m still getting wrong.</p>
<ul>
<li>Try Speechwave: <a href="https://speechwave.live" target="_blank" rel="noopener noreffer ">speechwave.live</a></li>
<li>Read the code: <a href="https://github.com/speechwave-live/speechwave" target="_blank" rel="noopener noreffer ">github.com/speechwave-live/speechwave</a></li>
<li>Tour the internals: <a href="https://docs.speechwave.live/dev/explainer/index.html" target="_blank" rel="noopener noreffer ">codebase explainer</a></li>
<li>Peek at the AI-assisted <a href="https://docs.speechwave.live/dev/course.html" target="_blank" rel="noopener noreffer ">short course for Ruby developers</a></li>
</ul>
]]></description></item></channel></rss>