Jekyll2023-01-29T18:28:34+00:00https://yafetn.github.io/feed.xmlThis & ThatA little bit of this and a little bit of that.So Good They Can’t Lay You Off?2023-01-20T00:00:00+00:002023-01-20T00:00:00+00:00https://yafetn.github.io/2023/01/20/so-good-they-cant-lay-you-off<p><img src="/assets/img-broadway-and-cedar.jpeg" alt="" /></p>
<p>We already know that you can be <a href="https://www.calnewport.com/books/so-good/">So Good They Can’t Ignore You</a>
(book review hopefully coming soon!), but can you be <strong>So Good They Can’t Lay <em>You</em> Off</strong> either?</p>
<p>I would think if the former is possible, then the latter is as well. Well, at least in a way.</p>
<p>As someone who got caught up in the tech world’s recent round of job cuts, I found myself thinking
if there was something different I could have done to avert that outcome in the first place. Questions like “Could I have closed out more tickets?”, “Could I have done them faster?” floated to mind, and yet I
felt like that wouldn’t have spared me either.</p>
<p>The truth of the matter is, I was not irreplaceable at work. In the words of Cal Newport, I did not have
rare and valuable skills – what he calls “career capital.” And I realize now that I was too comfortable
in the (admittedly few) skills and tools I was good at, rarely stretching myself for “deliberate practice.”</p>
<p>However, I can vouch for those qualities not being enough to save one from the proverbial axe, on
account of several aquintances that have also been laid off who possessed incredible skills. So what gives?</p>
<p>Sure, people with enough career capital stored up may get laid off just like the rest, but I figure it
does not affect them as negatively as it does others. Their professional networks can be tapped for new opportunities, relevant skills turned into a new venture, or something else conjured up. In the end, it
becomes a simple turning page in one’s career as oppossed to a significant hurdle to overcome. While they may not be able to avoid getting laid off – as these things tend to be haphazard – they don’t become
<em>laid off</em>.</p>
<p>My hope is to adopt the <em>craftman mindset</em> as Newport describes it, and engage in deliberate practice
where I can so that even if I get laid off again, I don’t end up <em>laid off</em>.</p>The Unreasonable Effectiveness of Simple Binary Encoding (SBE)2023-01-12T00:00:00+00:002023-01-12T00:00:00+00:00https://yafetn.github.io/2023/01/12/sbe<p><img src="/assets/img-lamppost.jpeg" alt="" /></p>
<h3 id="introduction">Introduction</h3>
<p>Simple Binary Encoding (SBE) is a codec format specified by the Financial
Information eXchange (FIX) Trading Community for use in high-performance trading systems.
It lives in Layer 6 (Presentation Layer) of the <a href="https://en.wikipedia.org/wiki/OSI_model">OSI model</a>, and deals with how
trading messages between different systems are represented on the wire.
Below, we’ll see why it may make sense to leverage its compactness and performance in
non-financial settings as well, provided its obscurity and some quirks are deemed tolerable for the
use-case.</p>
<h3 id="why-yet-another-codec">Why yet another codec?</h3>
<p>For a lot of systems, passing around JSON data is perfectly suitable. It is self-describing, human-readable,
and perhaps above all – has the benefit of being easy to integrate with almost anywhere.
It is the lingua franca of interprocess communication nowadays, and one would be hard pressed to find a
language or a library that doesn’t support it.</p>
<p>In some respects though, JSON is not as efficient as one would want a codec to be.</p>
<figure class="highlight"><pre><code class="language-json" data-lang="json"><span class="p">{</span><span class="w">
</span><span class="nl">"students"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
</span><span class="p">{</span><span class="w">
</span><span class="nl">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"First Last"</span><span class="p">,</span><span class="w">
</span><span class="err">...</span><span class="w">
</span><span class="p">},</span><span class="w">
</span><span class="p">{</span><span class="w">
</span><span class="nl">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"First1 Last1"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="err">...</span><span class="w">
</span><span class="p">]</span><span class="w">
</span><span class="err">...</span><span class="w">
</span><span class="p">}</span></code></pre></figure>
<p>Notice in the above snippet how the key <code class="language-plaintext highlighter-rouge">name</code> is repeated for every student element in the
<code class="language-plaintext highlighter-rouge">students</code> array. If we already know the schema of the student model, there’s no need
to repeatedly have the <code class="language-plaintext highlighter-rouge">key=value</code> structure and, moreover, use that for over the wire
transmission. Imagine how odd it’d be if we referenced the part of speech of each word
we spoke – something like
<code class="language-plaintext highlighter-rouge">Subject:I Verb:have Article:an Object:apple</code>.
The density of information we’d pass on to each other via spech would be so much smaller,<br />
and we would be wasting precious time and brain cycles speaking like that.</p>
<p>Instead, each language has some grammar (schema, in our case) that’s learned ahead of time. And
so when the time comes to decode some prose or speech, the receiver can infer the grammar by the
arrangement of the different words. Of course, this leads to some ambiguity in natural languages
like English – which we should have no room for in computing. In similar vein, SBE schemas are
shared off-channel and the data on the wire is much more compact because there’s no <code class="language-plaintext highlighter-rouge">key=value</code> structure,
just a series of <code class="language-plaintext highlighter-rouge">value1|value2|...</code>. This leads to challenges of its own, such as:</p>
<ul>
<li>How do we know where <code class="language-plaintext highlighter-rouge">value1</code> ends and <code class="language-plaintext highlighter-rouge">value2</code> begins?</li>
<li>What if there’s a change in schema?
and many others.</li>
</ul>
<h3 id="so-what">So what?</h3>
<p>We looked at how JSON repeats the <code class="language-plaintext highlighter-rouge">key=value</code> structure, which makes the codec human
readable but is very inefficient. And we also introduced the notion of a schema that’s shared
with the decoder separately from the data it needs to decode. The schema lays out the ordering
and lengths of the different values that the decoder may encounter in a payload, and
that’s how something like <code class="language-plaintext highlighter-rouge">value1|value2|value3|...</code> could be understood by the receiving
system. The compact binary layout of SBE enables it to have desirable characteristics for low-latency
and high-throughput applications, reducing bandwidth, compute, and memory utilization.</p>
<h3 id="advantages">Advantages</h3>
<ul>
<li>Simple native binary types reduce complexity and improve performance during (de)serialization</li>
<li>Messages are compactly packed since keys (field names) are not sent over the wire</li>
<li>Off-channel schema exchange reduces overhead (only messages are sent over the wire, not their schema)</li>
<li>Strict schema versioning</li>
<li>Enables copy- and allocation-free encoding/decoding</li>
</ul>
<h3 id="disadvantages">Disadvantages</h3>
<ul>
<li>Fields in the schema cannot be reordered</li>
<li>Variable length fields (such as strings) must follow fixed-length fields</li>
<li>Payloads are not self-describing, and thus require a decoder to be human-readable</li>
<li>SBE is largely confined to high performance finance/trading applications</li>
</ul>
<h3 id="resources">Resources</h3>
<ul>
<li><a href="https://aeroncookbook.com/simple-binary-encoding/overview/">Aeron Cookbook - SBE</a></li>
<li><a href="https://github.com/real-logic/simple-binary-encoding">SBE Reference Implementation by real-logic</a></li>
<li><a href="https://www.fixtrading.org/standards/sbe-online/">FIX Trading Community Reference</a></li>
</ul>