<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Muntazir Fadhel</title>
    <description>The Personal Blog of Muntazir Fadhel</description>
    <link>https://mfadhel.com/</link>
    <atom:link href="https://mfadhel.com/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Tue, 27 Oct 2026 17:06:23 +0000</pubDate>
    <lastBuildDate>Tue, 27 Oct 2026 17:06:23 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>The MCP C# SDK&apos;s Copilot instructions tell agents to use a class Copilot deleted</title>
        <description>&lt;p&gt;Every coding agent opens the same file first. Before it writes anything it reads the repository’s instruction file (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLAUDE.md&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AGENTS.md&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.github/copilot-instructions.md&lt;/code&gt;, depending on the agent) and takes what that file says about the code as a starting point.&lt;/p&gt;

&lt;p&gt;I build &lt;a href=&quot;https://striff.io&quot;&gt;Striff&lt;/a&gt;, a tool that checks docs against code on pull requests. I was running it over public repositories when it flagged line 258 of the instruction file in the &lt;a href=&quot;https://github.com/modelcontextprotocol/csharp-sdk&quot;&gt;official C# SDK for the Model Context Protocol&lt;/a&gt;, the protocol whose whole job is to give models accurate context:&lt;/p&gt;

&lt;div class=&quot;fig&quot;&gt;
&lt;div class=&quot;ghfile&quot;&gt;
&lt;div class=&quot;ghfile-bar&quot;&gt;&lt;span class=&quot;ghfile-crumbs&quot;&gt;csharp-sdk &lt;i&gt;/&lt;/i&gt; .github &lt;i&gt;/&lt;/i&gt; &lt;b&gt;copilot-instructions.md&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;ghfile-tabs&quot;&gt;&lt;span class=&quot;is-on&quot;&gt;Preview&lt;/span&gt;&lt;span&gt;Code&lt;/span&gt;&lt;span&gt;Blame&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;ghfile-body&quot;&gt;
&lt;p class=&quot;ghfile-h&quot;&gt;Server Implementation Architecture&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;ghfile-ln&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;ghfile-text&quot;&gt;Server primitives (tools, prompts, resources) are discovered via reflection using attributes&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;ghfile-ln&quot;&gt;257&lt;/span&gt;&lt;span class=&quot;ghfile-text&quot;&gt;Support both attribute-based registration (&lt;code&gt;WithTools&amp;lt;T&amp;gt;()&lt;/code&gt;) and instance-based (&lt;code&gt;WithTools(target)&lt;/code&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;is-hl&quot;&gt;&lt;span class=&quot;ghfile-ln&quot;&gt;258&lt;/span&gt;&lt;span class=&quot;ghfile-text&quot;&gt;Use &lt;mark&gt;McpServerFactory&lt;/mark&gt; to create server instances with configured options&lt;br /&gt;&lt;span class=&quot;ghfile-callout&quot;&gt;&lt;b&gt;Not in the code.&lt;/b&gt; Deleted 2 Dec 2025 in &lt;a href=&quot;https://github.com/modelcontextprotocol/csharp-sdk/pull/985&quot;&gt;#985&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p class=&quot;fig-caption&quot;&gt;&lt;a href=&quot;https://github.com/modelcontextprotocol/csharp-sdk/blob/c40ee044fd415c70da5176c749cb5ef02f2b59f6/.github/copilot-instructions.md?plain=1#L258&quot;&gt;The line, at the commit I checked&lt;/a&gt;. This file exists to brief a coding agent before it writes anything.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;McpServerFactory&lt;/code&gt; does not exist. Search the repository for the name and you get one result: this line, in the file Copilot reads first. The class was marked obsolete in September 2025 with a note to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;McpServer.Create&lt;/code&gt; instead, and deleted in December.&lt;/p&gt;

&lt;!--more--&gt;

&lt;div class=&quot;callout&quot;&gt;Copilot wrote that instruction. Seven weeks later, Copilot deleted the class it names. Ten months on, the line is still there.&lt;/div&gt;

&lt;p&gt;The cost of this one line is small. An agent that takes line 258 at face value writes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;McpServerFactory&lt;/code&gt;, watches the build fail, and goes looking for what it should have done. A more careful agent greps for the name first, finds nothing, and does the same search a few turns earlier. Either way it is a few wasted turns. I wrote this up because of what it says about every other sentence in that file, and in yours.&lt;/p&gt;

&lt;h2 id=&quot;how-the-line-got-there-and-stayed&quot;&gt;How the line got there and stayed&lt;/h2&gt;

&lt;p&gt;At no point in the history of this line was anyone looking at the instruction and the class at the same time.&lt;/p&gt;

&lt;div class=&quot;fig&quot;&gt;
&lt;p class=&quot;fig-title&quot;&gt;One line, five commits&lt;/p&gt;
&lt;ol class=&quot;timeline&quot;&gt;
&lt;li&gt;&lt;span class=&quot;tl-date&quot;&gt;16 Sep 2025&lt;/span&gt;&lt;span class=&quot;tl-body&quot;&gt;&lt;code&gt;McpServerFactory&lt;/code&gt; is marked &lt;code&gt;[Obsolete]&lt;/code&gt;: &lt;em&gt;&quot;Use McpServer.Create instead.&quot;&lt;/em&gt; &lt;a href=&quot;https://github.com/modelcontextprotocol/csharp-sdk/commit/38b4a269&quot;&gt;38b4a26&lt;/a&gt;. A week later the note gains a second sentence: &lt;em&gt;&quot;This member will be removed in a subsequent release.&quot;&lt;/em&gt; &lt;a href=&quot;https://github.com/modelcontextprotocol/csharp-sdk/commit/5f992994&quot;&gt;5f99299&lt;/a&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;tl-date&quot;&gt;13 Oct 2025&lt;/span&gt;&lt;span class=&quot;tl-body&quot;&gt;Copilot opens &lt;a href=&quot;https://github.com/modelcontextprotocol/csharp-sdk/pull/858&quot;&gt;#858&lt;/a&gt;, &quot;Set up Copilot instructions for repository&quot;, a long and mostly accurate briefing. Two maintainers review it and it is merged. The instruction to use &lt;code&gt;McpServerFactory&lt;/code&gt;, by then obsolete for four weeks, is line 222.&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;is-del&quot;&gt;&lt;span class=&quot;tl-date&quot;&gt;2 Dec 2025&lt;/span&gt;&lt;span class=&quot;tl-body&quot;&gt;&lt;a href=&quot;https://github.com/modelcontextprotocol/csharp-sdk/pull/985&quot;&gt;#985&lt;/a&gt;, &quot;Remove obsolete APIs from codebase&quot;, deletes &lt;code&gt;McpServerFactory.cs&lt;/code&gt;. Authored by Copilot, co-authored by three of the project&apos;s developers. The instructions file is not in the diff, so nobody reviewing the removal had a reason to open it.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;tl-date&quot;&gt;Apr to Aug 2026&lt;/span&gt;&lt;span class=&quot;tl-body&quot;&gt;Four more commits edit the instructions file. None touches the line, which drifts down to 258.&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;is-now&quot;&gt;&lt;span class=&quot;tl-date&quot;&gt;26 Sep 2026&lt;/span&gt;&lt;span class=&quot;tl-body&quot;&gt;Line 258 is still there.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;The people who reviewed the instructions read a long document that was almost entirely right. The people who reviewed the removal read a diff, and the document was not in it. A document and the code it describes live in different files, and a pull request shows only the files it changes.&lt;/p&gt;

&lt;h2 id=&quot;why-your-pipeline-does-not-catch-this&quot;&gt;Why your pipeline does not catch this&lt;/h2&gt;

&lt;p&gt;Design docs used to have one reader, a person, who noticed when a sentence had stopped being true. Now the document is an input to code generation. The practice has a name, spec-driven development, and a toolchain: GitHub’s Spec Kit, AWS’s Kiro, Tessl, and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AGENTS.md&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLAUDE.md&lt;/code&gt; files that brief an agent before it touches anything. Birgitta Böckeler’s &lt;a href=&quot;https://martinfowler.com/articles/exploring-gen-ai/sdd-3-tools.html&quot;&gt;survey of Spec Kit, Kiro and Tessl&lt;/a&gt; sorts the practice into three levels: spec-first, where the spec drives one task; spec-anchored, where it is kept afterwards and the feature keeps evolving through it; and spec-as-source, where a human edits only the spec and never the code. Everything past the first level depends on the spec staying true after the task ends, and that is the step the tooling has not caught up with.&lt;/p&gt;

&lt;p&gt;In &lt;a href=&quot;https://striff.io/blog/architecture-matters-more-not-less#so-we-measured-it-ourselves&quot;&gt;a survey of 335 open-source repositories&lt;/a&gt; that document their architecture, 63% already give their coding agents documents to build from, and 8% of those run any tool that checks the code against them. The survey is mine, and the link goes to how it was counted.&lt;/p&gt;

&lt;p&gt;Code has a compiler and a test runner to tell you when it is wrong. Prose has a few checks too: rustdoc warns on a broken intra-doc link, doctests run the examples, and a link checker catches a dead URL. But “Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;McpServerFactory&lt;/code&gt;” is a plain sentence, and none of those tools reads sentences, so it passes all of them.&lt;/p&gt;

&lt;p&gt;The obvious answer is to grep. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git grep -w McpServerFactory -- &apos;*.md&apos;&lt;/code&gt; takes a second, and if every removal PR ran it, this post would have little to show you. I would like everyone to do that, and it is the first item in the list at the end. It only catches the kind of drift that has a name in it, though, and the expensive kind does not.&lt;/p&gt;

&lt;div class=&quot;fig&quot;&gt;
&lt;p class=&quot;fig-title&quot;&gt;Two ways this goes wrong&lt;/p&gt;
&lt;div class=&quot;outcomes&quot;&gt;
&lt;div class=&quot;outcome outcome--amber&quot;&gt;&lt;p class=&quot;outcome-name&quot;&gt;The agent follows a sentence that is no longer true&lt;/p&gt;&lt;p class=&quot;outcome-desc&quot;&gt;&lt;em&gt;&quot;Use &lt;code&gt;McpServerFactory&lt;/code&gt;.&quot;&lt;/em&gt; The build breaks, the agent recovers, you pay in turns and tokens. If the sentence describes a pattern rather than a class, the build does not break, and the agent reproduces a design the team retired.&lt;/p&gt;&lt;/div&gt;
&lt;div class=&quot;outcome outcome--danger&quot;&gt;&lt;p class=&quot;outcome-name&quot;&gt;The agent ignores a sentence that is still true&lt;/p&gt;&lt;p class=&quot;outcome-desc&quot;&gt;&lt;em&gt;&quot;Controllers go through the service layer.&quot; &quot;&lt;code&gt;core&lt;/code&gt; never imports from &lt;code&gt;plugins&lt;/code&gt;.&quot;&lt;/em&gt; The agent takes a shortcut. The code compiles, the tests pass, the diff looks fine, and the document that forbade it is not in the diff. Merged.&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The second case is how architecture erodes: a hundred small changes that each compiled and each passed review as a diff, while contradicting a sentence nobody had open. A year later the layering the team agreed on describes a system that no longer exists. Grep cannot find that, because there is no token to search for. Checking “&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;core&lt;/code&gt; never imports from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;plugins&lt;/code&gt;” means turning the sentence into a question about the dependency graph and asking it at both ends of the pull request.&lt;/p&gt;

&lt;h2 id=&quot;other-repositories&quot;&gt;Other repositories&lt;/h2&gt;

&lt;p&gt;I led with the MCP line, but lines like it were not hard to find. In the same run, &lt;a href=&quot;https://github.com/apache/dolphinscheduler/blob/7cf1677133624484d2a8e70b4cc7bcf9cdb8ef6d/docs/docs/en/contribute/backend/spi/registry.md?plain=1#L20&quot;&gt;DolphinScheduler&lt;/a&gt;’s contributor guide tells contributors to implement an interface the repository no longer has, &lt;a href=&quot;https://github.com/apache/pinot/blob/04cca1a58dc23155e1b1fd355fe5da0b633622d3/pinot-sql-ddl/DESIGN.md?plain=1#L97&quot;&gt;Apache Pinot&lt;/a&gt;’s design note says its SQL DDL module depends only on three things while the module’s build and imports pull in a fourth, and &lt;a href=&quot;https://github.com/dotnet/BenchmarkDotNet/blob/962da56e99ff7ab706c3c6f0aeb24e4af91a0d4f/docs/articles/configs/exporters.md?plain=1#L101&quot;&gt;BenchmarkDotNet&lt;/a&gt; documents four properties of an interface that no longer exists.&lt;/p&gt;

&lt;p&gt;These are well-maintained projects with careful reviewers, and their review process is fine. It just never puts the sentence and the code in front of the same person.&lt;/p&gt;

&lt;p&gt;A stale name can also get copied. The README of &lt;a href=&quot;https://github.com/yegor256/cactoos&quot;&gt;yegor256/cactoos&lt;/a&gt; kept &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;StickyList&lt;/code&gt; in a comparison table years after the class was &lt;a href=&quot;https://github.com/yegor256/cactoos/commit/be02845&quot;&gt;renamed&lt;/a&gt; and then &lt;a href=&quot;https://github.com/yegor256/cactoos/commit/eed03c1fc05217eeda0564999cae2c87709b1e13&quot;&gt;removed&lt;/a&gt;. In April 2026 an agent asked to describe the architecture &lt;a href=&quot;https://github.com/yegor256/cactoos/commit/18a0c8ad8d8b64d6bbb62fa36e668f967afda2ac&quot;&gt;wrote a new section&lt;/a&gt; that told readers to opt in to caching “with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sticky&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;StickyList&lt;/code&gt;”.&lt;/p&gt;

&lt;h2 id=&quot;what-to-do-about-it&quot;&gt;What to do about it&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Treat your agent instruction files as code, because agents build from them. When you delete or rename a type, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git grep -w OldName -- &apos;*.md&apos;&lt;/code&gt; takes a second, and IDE rename refactorings usually skip markdown.&lt;/li&gt;
  &lt;li&gt;Keep them short, and prefer rules to names. “Controllers never call repositories directly” stays true across a hundred refactors. A class name is a claim that can go stale on the next one.&lt;/li&gt;
  &lt;li&gt;Have the docs checked on the pull request, where the change that contradicts them is being reviewed, by something that reads the sentence and the code together.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;striff-the-tool-that-found-these&quot;&gt;Striff, the tool that found these&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://striff.io&quot;&gt;Striff&lt;/a&gt; is a GitHub App, free on public repositories. It parses both revisions of a pull request, reads the documents already in the repository, turns each sentence that makes a claim about the code into a rule, and checks the rule at the base and the head. A name the repository no longer has, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;McpServerFactory&lt;/code&gt;, is reported against the document that uses it, with the commit that removed the type. A rule the change broke is reported against the change. You do not write any rules yourself, because it uses the ones your team already wrote down and your agents are already reading.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://striff.io/#diagram&quot;&gt;Here is a real check&lt;/a&gt;, unedited, from a public pull request. The run these examples came from covered 609 public pull requests. Striff read 7,161 rules out of those repositories’ docs, could answer 5,674 of them from the parsed code, and found 97 that the change under review had broken. &lt;a href=&quot;https://striff.io/blog/design-docs-are-enforceable-now#how-often-it-fires&quot;&gt;The full breakdown&lt;/a&gt; is on the Striff blog.&lt;/p&gt;

&lt;h2 id=&quot;the-fixes&quot;&gt;The fixes&lt;/h2&gt;

&lt;p&gt;I opened fixes for the MCP line and the cactoos sentence before publishing this. &lt;a href=&quot;https://github.com/yegor256/cactoos/pull/1959&quot;&gt;yegor256/cactoos#1959&lt;/a&gt; was merged the next day. &lt;a href=&quot;https://github.com/modelcontextprotocol/csharp-sdk/pull/1892&quot;&gt;modelcontextprotocol/csharp-sdk#1892&lt;/a&gt; (with &lt;a href=&quot;https://github.com/modelcontextprotocol/csharp-sdk/issues/1893&quot;&gt;issue #1893&lt;/a&gt;) is still open.&lt;/p&gt;
</description>
        <pubDate>Sat, 26 Sep 2026 09:00:00 +0000</pubDate>
        <link>https://mfadhel.com/copilot-instructions-deleted-class/</link>
        <guid isPermaLink="true">https://mfadhel.com/copilot-instructions-deleted-class/</guid>
        
        <category>coding agents</category>
        
        <category>documentation</category>
        
        <category>architecture</category>
        
        <category>software design</category>
        
        
      </item>
    
      <item>
        <title>Building a Production Neurosymbolic Pipeline for Scientific Discourse Graphs</title>
        <description>&lt;p&gt;LLMs are competent at reading scientific papers. They are not yet competent at producing knowledge graphs that downstream systems can trust. The output is plausible, well-formatted, and frequently wrong in ways that only become visible after the graph is queried, joined to other data, or used to train another model.&lt;/p&gt;

&lt;p&gt;I built &lt;a href=&quot;https://fylo.io/&quot;&gt;Fylo&lt;/a&gt;’s ingestion pipeline, the part that turns scientific papers into a typed discourse graph of claims, evidence, hypotheses, and research questions. The interesting engineering was never the LLM extraction. It was the symbolic scaffolding around it that turned a noisy generative process into a graph reliable enough that downstream systems could join against it without re-checking every node.&lt;/p&gt;

&lt;div id=&quot;fylo-graph-intro&quot; style=&quot;margin:24px auto;max-width:700px;border:1px solid rgba(15,23,42,0.12);border-radius:12px;overflow:hidden;background:#0f172a;&quot;&gt;&lt;/div&gt;
&lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;

&lt;script&gt;
(function(){
var nodes=[
{id:&quot;RQ1&quot;,type:&quot;ResearchQuestion&quot;,title:&quot;How do bioelectric circuits control anatomical outcomes?&quot;},
{id:&quot;A1&quot;,type:&quot;Association&quot;,title:&quot;Gap junction proteins and ion channel expression regulate bioelectrical signals&quot;},
{id:&quot;A2&quot;,type:&quot;Association&quot;,title:&quot;Turing-like patterns arise from bioelectric mechanisms&quot;},
{id:&quot;A3&quot;,type:&quot;Association&quot;,title:&quot;Epithelial tissue geometry directs bioelectric field&quot;},
{id:&quot;A4&quot;,type:&quot;Association&quot;,title:&quot;Connexin43 regulates joint location in zebrafish fins&quot;},
{id:&quot;A5&quot;,type:&quot;Association&quot;,title:&quot;Calcium oscillations coordinate feather mesenchymal cell movement&quot;},
{id:&quot;F1&quot;,type:&quot;Factor&quot;,title:&quot;Morphogenetic outcomes&quot;},
{id:&quot;F2&quot;,type:&quot;Factor&quot;,title:&quot;TRPC6&quot;},
{id:&quot;F3&quot;,type:&quot;Factor&quot;,title:&quot;Membrane potential in mammalian cancer cells&quot;},
{id:&quot;F4&quot;,type:&quot;Factor&quot;,title:&quot;Gene expression domains&quot;},
{id:&quot;F5&quot;,type:&quot;Factor&quot;,title:&quot;Endogenous bioelectric gradients&quot;},
{id:&quot;F6&quot;,type:&quot;Factor&quot;,title:&quot;H+/K+-ATPase activity and membrane potential&quot;},
{id:&quot;F7&quot;,type:&quot;Factor&quot;,title:&quot;PI3K-mediated electrotaxis of neural progenitor cells&quot;},
{id:&quot;F8&quot;,type:&quot;Factor&quot;,title:&quot;Osteogenic and Chondrogenic Master Genes expression&quot;},
{id:&quot;F9&quot;,type:&quot;Factor&quot;,title:&quot;Size of zebrafish fins&quot;},
{id:&quot;EL1&quot;,type:&quot;EvidenceLine&quot;,title:&quot;hERG1 channel conformation impacts cancer progression&quot;}
];
var links=[
{source:&quot;RQ1&quot;,target:&quot;A1&quot;,type:&quot;motivates&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;A2&quot;,type:&quot;motivates&quot;,conf:.8},
{source:&quot;RQ1&quot;,target:&quot;A3&quot;,type:&quot;motivates&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;A4&quot;,type:&quot;motivates&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;A5&quot;,type:&quot;motivates&quot;,conf:.7},
{source:&quot;RQ1&quot;,target:&quot;F1&quot;,type:&quot;addresses&quot;,conf:.8},
{source:&quot;RQ1&quot;,target:&quot;F2&quot;,type:&quot;addresses&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;F4&quot;,type:&quot;addresses&quot;,conf:.85},
{source:&quot;RQ1&quot;,target:&quot;F5&quot;,type:&quot;addresses&quot;,conf:.8},
{source:&quot;RQ1&quot;,target:&quot;F6&quot;,type:&quot;addresses&quot;,conf:.6},
{source:&quot;RQ1&quot;,target:&quot;F7&quot;,type:&quot;addresses&quot;,conf:.8},
{source:&quot;RQ1&quot;,target:&quot;F8&quot;,type:&quot;addresses&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;F9&quot;,type:&quot;addresses&quot;,conf:.9},
{source:&quot;A1&quot;,target:&quot;F2&quot;,type:&quot;arg0&quot;,conf:1},
{source:&quot;A1&quot;,target:&quot;F3&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A1&quot;,target:&quot;F1&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A1&quot;,target:&quot;F4&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A1&quot;,target:&quot;F6&quot;,type:&quot;arg0&quot;,conf:.8},
{source:&quot;A1&quot;,target:&quot;F8&quot;,type:&quot;arg1&quot;,conf:.8},
{source:&quot;A2&quot;,target:&quot;F2&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A3&quot;,target:&quot;F2&quot;,type:&quot;arg0&quot;,conf:.9},
{source:&quot;A3&quot;,target:&quot;F5&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A4&quot;,target:&quot;F7&quot;,type:&quot;arg0&quot;,conf:.8},
{source:&quot;A4&quot;,target:&quot;F9&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;EL1&quot;,target:&quot;A1&quot;,type:&quot;supports&quot;,conf:.9}
];
var colors={ResearchQuestion:&quot;#fbbf24&quot;,Association:&quot;#a78bfa&quot;,Factor:&quot;#34d399&quot;,EvidenceLine:&quot;#fb7185&quot;};
var edgeColors={motivates:&quot;#60a5fa&quot;,addresses:&quot;#60a5fa&quot;,arg0:&quot;#fbbf24&quot;,arg1:&quot;#fbbf24&quot;,supports:&quot;#34d399&quot;};
var sizes={ResearchQuestion:15,Association:10,Factor:8,EvidenceLine:8};
var W=700,H=500;
var svg=d3.select(&quot;#fylo-graph-intro&quot;).append(&quot;svg&quot;).attr(&quot;viewBox&quot;,&quot;0 0 &quot;+W+&quot; &quot;+H).attr(&quot;width&quot;,&quot;100%&quot;).attr(&quot;height&quot;,&quot;100%&quot;);
var g=svg.append(&quot;g&quot;);
svg.call(d3.zoom().scaleExtent([.5,4]).on(&quot;zoom&quot;,function(e){g.attr(&quot;transform&quot;,e.transform)}));
var link=g.append(&quot;g&quot;).selectAll(&quot;line&quot;).data(links).join(&quot;line&quot;).attr(&quot;stroke&quot;,function(d){return edgeColors[d.type]||&quot;#64748b&quot;}).attr(&quot;stroke-width&quot;,function(d){return d.conf*2}).attr(&quot;stroke-opacity&quot;,.5);
var node=g.append(&quot;g&quot;).selectAll(&quot;g&quot;).data(nodes).join(&quot;g&quot;).call(d3.drag().on(&quot;start&quot;,dragstart).on(&quot;drag&quot;,dragged).on(&quot;end&quot;,dragend));
node.append(&quot;circle&quot;).attr(&quot;r&quot;,function(d){return sizes[d.type]||8}).attr(&quot;fill&quot;,function(d){return colors[d.type]||&quot;#64748b&quot;}).attr(&quot;stroke&quot;,&quot;rgba(255,255,255,0.2)&quot;).attr(&quot;stroke-width&quot;,1.5);
node.append(&quot;text&quot;).text(function(d){return d.title.length&gt;30?d.title.substring(0,30)+&quot;...&quot;:d.title}).attr(&quot;dy&quot;,function(d){return(sizes[d.type]||8)+12}).attr(&quot;text-anchor&quot;,&quot;middle&quot;).attr(&quot;fill&quot;,&quot;#94a3b8&quot;).attr(&quot;font-size&quot;,&quot;7.5px&quot;).attr(&quot;font-family&quot;,&quot;IBM Plex Sans, system-ui, sans-serif&quot;);
var tooltip=d3.select(&quot;#fylo-graph-intro&quot;).append(&quot;div&quot;).style(&quot;position&quot;,&quot;absolute&quot;).style(&quot;display&quot;,&quot;none&quot;).style(&quot;background&quot;,&quot;rgba(30,41,59,.95)&quot;).style(&quot;border&quot;,&quot;1px solid rgba(255,255,255,.1)&quot;).style(&quot;border-radius&quot;,&quot;6px&quot;).style(&quot;padding&quot;,&quot;8px 12px&quot;).style(&quot;font-size&quot;,&quot;11px&quot;).style(&quot;color&quot;,&quot;#e2e8f0&quot;).style(&quot;font-family&quot;,&quot;IBM Plex Sans, system-ui, sans-serif&quot;).style(&quot;pointer-events&quot;,&quot;none&quot;).style(&quot;max-width&quot;,&quot;260px&quot;).style(&quot;z-index&quot;,&quot;10&quot;);
node.on(&quot;mouseover&quot;,function(e,d){tooltip.style(&quot;display&quot;,&quot;block&quot;).html(&quot;&lt;strong style=&apos;color:&quot;+colors[d.type]+&quot;&apos;&gt;&quot;+d.type+&quot;&lt;/strong&gt;&lt;br/&gt;&quot;+d.title)}).on(&quot;mousemove&quot;,function(e){var rect=document.getElementById(&quot;fylo-graph-intro&quot;).getBoundingClientRect();tooltip.style(&quot;left&quot;,(e.clientX-rect.left+12)+&quot;px&quot;).style(&quot;top&quot;,(e.clientY-rect.top-20)+&quot;px&quot;)}).on(&quot;mouseout&quot;,function(){tooltip.style(&quot;display&quot;,&quot;none&quot;)});
var sim=d3.forceSimulation(nodes).force(&quot;link&quot;,d3.forceLink(links).id(function(d){return d.id}).distance(55)).force(&quot;charge&quot;,d3.forceManyBody().strength(-180)).force(&quot;center&quot;,d3.forceCenter(W/2,H/2)).force(&quot;collision&quot;,d3.forceCollide().radius(28));
sim.on(&quot;tick&quot;,function(){link.attr(&quot;x1&quot;,function(d){return d.source.x}).attr(&quot;y1&quot;,function(d){return d.source.y}).attr(&quot;x2&quot;,function(d){return d.target.x}).attr(&quot;y2&quot;,function(d){return d.target.y});node.attr(&quot;transform&quot;,function(d){return&quot;translate(&quot;+d.x+&quot;,&quot;+d.y+&quot;)&quot;})});
function dragstart(e,d){if(!e.active)sim.alphaTarget(.3).restart();d.fx=d.x;d.fy=d.y}
function dragged(e,d){d.fx=e.x;d.fy=e.y}
function dragend(e,d){if(!e.active)sim.alphaTarget(0);d.fx=null;d.fy=null}
var legend=d3.select(&quot;#fylo-graph-intro&quot;).style(&quot;position&quot;,&quot;relative&quot;).append(&quot;div&quot;).style(&quot;position&quot;,&quot;absolute&quot;).style(&quot;bottom&quot;,&quot;8px&quot;).style(&quot;left&quot;,&quot;8px&quot;).style(&quot;display&quot;,&quot;flex&quot;).style(&quot;gap&quot;,&quot;10px&quot;).style(&quot;font-size&quot;,&quot;10px&quot;).style(&quot;font-family&quot;,&quot;IBM Plex Sans, system-ui, sans-serif&quot;);
Object.entries(colors).forEach(function(kv){legend.append(&quot;span&quot;).style(&quot;display&quot;,&quot;flex&quot;).style(&quot;align-items&quot;,&quot;center&quot;).style(&quot;gap&quot;,&quot;4px&quot;).style(&quot;color&quot;,&quot;#94a3b8&quot;).html(&quot;&lt;span style=&apos;display:inline-block;width:8px;height:8px;border-radius:50%;background:&quot;+kv[1]+&quot;&apos;&gt;&lt;/span&gt;&quot;+kv[0])})
})();
&lt;/script&gt;

&lt;p&gt;This post covers the three design decisions that mattered most: a ShEx schema as executable contract, a phased extraction pipeline that closes the validator-LLM loop, and a three-tier merge policy that handles cross-document identity correctly. The same staging, a language model proposing and a program deciding, runs behind &lt;a href=&quot;https://striff.io&quot;&gt;striff.io&lt;/a&gt;, which checks pull requests against a repository’s own architecture documents.&lt;/p&gt;

&lt;!--more--&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;schema-as-executable-contract&quot;&gt;Schema as Executable Contract&lt;/h2&gt;

&lt;p&gt;Discourse graphs need a stricter schema than most domain models. Nodes carry semantic role (claim, evidence, hypothesis), strict cardinality on outgoing edges, and IRI references that must resolve within the same graph. An Association claim missing its &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arg0&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arg1&lt;/code&gt; factors is structurally meaningless. A schema that lets these through is documentation, not validation.&lt;/p&gt;

&lt;p&gt;We chose ShEx (Shape Expressions) over JSON Schema or pydantic because ShEx natively expresses graph-level constraints: cardinality across edges, IRI references, shape disjunctions. The schema lives in a single &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.shex&lt;/code&gt; file, is machine-checkable through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pyshex&lt;/code&gt;, and is the single source of truth that everything else derives from.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/fylo-shex-association.svg&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The schema participates in two places. A curated excerpt is injected into the LLM system prompt so the model sees the constraints before generating. After extraction, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pyshex&lt;/code&gt;’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ShExEvaluator&lt;/code&gt; runs against the produced subgraph and rejects nodes that violate their shape definitions. The prompt-time injection biases the model toward valid output; the post-extraction validation catches the cases where the bias was insufficient.&lt;/p&gt;

&lt;p&gt;Edge confidence scores are clamped to [0, 1] and rounded at the validator boundary. Different LLM calls produce different confidence ranges, and without normalization at this point downstream analytics build on numerically unstable signals.&lt;/p&gt;

&lt;p&gt;ShEx handles structural constraints well but struggles with logical constraints across the graph, the kind that say “a hypothesis cannot be confirmed unless at least two non-overlapping evidence lines support it.” The architecture I would build today layers ShEx as the cheap structural gate that runs every pass, with Z3 as the more expensive semantic gate that runs at canonicalization time.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;closing-the-validator-llm-loop&quot;&gt;Closing the Validator-LLM Loop&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/images/fylo-three-phase-extraction.svg&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The standard approach has the LLM extract once and the validator either pass or fail the whole batch. The problem is that LLMs produce confident but malformed output, and re-running the same prompt with the same document reproduces the same errors.&lt;/p&gt;

&lt;p&gt;The pipeline I shipped at Fylo decomposes a single chunk into three sequential extraction phases, each with a specialized prompt and scope. Phase 1 extracts entities only, with the prompt explicitly forbidding edge calls. This produces a clean inventory that can be validated against node-level shapes before any relational reasoning happens. Phase 2 extracts relations only, with the Phase 1 entities passed back as context. New nodes are permitted only when an edge would otherwise be dangling. Phase 3 repairs orphans: any node that ended up disconnected gets a final pass where the LLM is shown the dangling nodes specifically and asked to either form connecting associations or accept that they should drop.&lt;/p&gt;

&lt;p&gt;This decomposition matters more than the prompts themselves. Phase 1 outputs are validated before Phase 2 starts, so Phase 2 produces edges guaranteed to reference real, validated nodes. Phase 3 addresses the failure mode where graphs become a pile of disconnected entities, by giving the model an explicit second chance with focused context.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/fylo-pipeline-overview.svg&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The regex-based LLM output parser had to go. Regex cannot reliably handle nested parentheses inside string literals, and the old parser silently dropped well-formed extractions whenever a string contained an unescaped quote. The first sign was an output graph that was consistently shallower and narrower than the expected structure: associations missing their factor edges, evidence lines that never connected to the claims they supported. The replacement uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ast.literal_eval&lt;/code&gt; rather than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eval&lt;/code&gt; for safety, and ships with full test coverage.&lt;/p&gt;

&lt;p&gt;The other change that mattered was tightening the schema prompt with explicit cardinality language. The Phase 1 prompt for Association nodes makes it unambiguous: every Association must include both an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arg0&lt;/code&gt; and an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arg1&lt;/code&gt; factor edge, or it will fail validation. This is the prompt-engineering equivalent of writing good error messages: tell the model exactly what will go wrong, before it goes wrong.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;cross-document-canonicalization&quot;&gt;Cross-Document Canonicalization&lt;/h2&gt;

&lt;p&gt;The obvious approach to cross-document deduplication is one similarity threshold and one merge action. This breaks immediately on a real schema. The right behaviour for a Factor node like “Protein X” is aggressive merging across documents because the same protein in two papers is the same protein. The right behaviour for an Association claim is the opposite. Two papers asserting that “Protein X reduces inflammation” might be expressing the same association or two subtly different claims with different evidence. Merging them collapses signal you cannot recover.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/fylo-merge-policies.svg&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The pipeline classifies node types into three merge policies. Aggressive types (factors, variables of interest, study designs, statistical methods) go through direct deduplication. When a new node arrives, its embedding is compared against role-filtered ANN candidates from the existing graph, and if the top candidate clears the threshold, the two nodes merge. Provenance is unioned, embeddings are weight-averaged based on accumulated confidence, and the lower-confidence node’s ID is rewritten across all incident edges.&lt;/p&gt;

&lt;p&gt;Cautious types (associations, hypotheses, research questions) use canonicalization rather than direct merging. Once enough cautious nodes of a given type accumulate, a synthetic canonical node is created with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CANON_&lt;/code&gt; prefix. Subsequent nodes either attach to the canonical via a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mentions&lt;/code&gt; edge, or trigger creation of a new canonical when they represent a distinct cluster. The originals stay in the graph with their citations and confidence scores intact. The canonical becomes the queryable hub; the originals remain the evidence behind it. A small set of structural types are never merged at all, because doing so would lose per-paper provenance.&lt;/p&gt;

&lt;p&gt;Role-filtered ANN search matters as much as the policy itself. A FAISS HNSW index returns candidates fast, but the candidate list will mix node types unless you filter at the search boundary. We restrict candidates to the same type as the query node before similarity scoring runs. Embedding maintenance under merge is the other non-obvious piece: the survivor’s embedding is a weight-averaged combination of the source vectors, upserted back into the ANN index so subsequent comparisons see the consolidated state.&lt;/p&gt;

&lt;p&gt;The test of cross-document canonicalization is whether the graph converges. A pipeline that adds papers and produces a graph that grows without becoming more connected is not building a knowledge graph.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;making-the-symbolic-layer-visible&quot;&gt;Making the Symbolic Layer Visible&lt;/h2&gt;

&lt;p&gt;Symbolic system improvements are abstract until you can see the graph. Telling a stakeholder that edge confidence scores are now properly normalized, or that cautious-type canonicalization is reducing duplicate hypotheses, communicates nothing. The same change rendered as a side-by-side visual diff communicates immediately.&lt;/p&gt;

&lt;div id=&quot;fylo-graph-viz&quot; style=&quot;margin:24px auto;max-width:700px;border:1px solid rgba(15,23,42,0.12);border-radius:12px;overflow:hidden;background:#0f172a;&quot;&gt;&lt;/div&gt;
&lt;script&gt;
(function(){
var nodes=[
{id:&quot;RQ1&quot;,type:&quot;ResearchQuestion&quot;,title:&quot;How do bioelectric circuits control anatomical outcomes?&quot;},
{id:&quot;A1&quot;,type:&quot;Association&quot;,title:&quot;Gap junction proteins and ion channel expression regulate bioelectrical signals&quot;},
{id:&quot;A2&quot;,type:&quot;Association&quot;,title:&quot;Turing-like patterns arise from bioelectric mechanisms&quot;},
{id:&quot;A3&quot;,type:&quot;Association&quot;,title:&quot;Epithelial tissue geometry directs bioelectric field&quot;},
{id:&quot;A4&quot;,type:&quot;Association&quot;,title:&quot;Connexin43 regulates joint location in zebrafish fins&quot;},
{id:&quot;A5&quot;,type:&quot;Association&quot;,title:&quot;Calcium oscillations coordinate feather mesenchymal cell movement&quot;},
{id:&quot;F1&quot;,type:&quot;Factor&quot;,title:&quot;Morphogenetic outcomes&quot;},
{id:&quot;F2&quot;,type:&quot;Factor&quot;,title:&quot;TRPC6&quot;},
{id:&quot;F3&quot;,type:&quot;Factor&quot;,title:&quot;Membrane potential in mammalian cancer cells&quot;},
{id:&quot;F4&quot;,type:&quot;Factor&quot;,title:&quot;Gene expression domains&quot;},
{id:&quot;F5&quot;,type:&quot;Factor&quot;,title:&quot;Endogenous bioelectric gradients&quot;},
{id:&quot;F6&quot;,type:&quot;Factor&quot;,title:&quot;H+/K+-ATPase activity and membrane potential&quot;},
{id:&quot;F7&quot;,type:&quot;Factor&quot;,title:&quot;PI3K-mediated electrotaxis of neural progenitor cells&quot;},
{id:&quot;F8&quot;,type:&quot;Factor&quot;,title:&quot;Osteogenic and Chondrogenic Master Genes expression&quot;},
{id:&quot;F9&quot;,type:&quot;Factor&quot;,title:&quot;Size of zebrafish fins&quot;},
{id:&quot;EL1&quot;,type:&quot;EvidenceLine&quot;,title:&quot;hERG1 channel conformation impacts cancer progression&quot;}
];
var links=[
{source:&quot;RQ1&quot;,target:&quot;A1&quot;,type:&quot;motivates&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;A2&quot;,type:&quot;motivates&quot;,conf:.8},
{source:&quot;RQ1&quot;,target:&quot;A3&quot;,type:&quot;motivates&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;A4&quot;,type:&quot;motivates&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;A5&quot;,type:&quot;motivates&quot;,conf:.7},
{source:&quot;RQ1&quot;,target:&quot;F1&quot;,type:&quot;addresses&quot;,conf:.8},
{source:&quot;RQ1&quot;,target:&quot;F2&quot;,type:&quot;addresses&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;F4&quot;,type:&quot;addresses&quot;,conf:.85},
{source:&quot;RQ1&quot;,target:&quot;F5&quot;,type:&quot;addresses&quot;,conf:.8},
{source:&quot;RQ1&quot;,target:&quot;F6&quot;,type:&quot;addresses&quot;,conf:.6},
{source:&quot;RQ1&quot;,target:&quot;F7&quot;,type:&quot;addresses&quot;,conf:.8},
{source:&quot;RQ1&quot;,target:&quot;F8&quot;,type:&quot;addresses&quot;,conf:.9},
{source:&quot;RQ1&quot;,target:&quot;F9&quot;,type:&quot;addresses&quot;,conf:.9},
{source:&quot;A1&quot;,target:&quot;F2&quot;,type:&quot;arg0&quot;,conf:1},
{source:&quot;A1&quot;,target:&quot;F3&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A1&quot;,target:&quot;F1&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A1&quot;,target:&quot;F4&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A1&quot;,target:&quot;F6&quot;,type:&quot;arg0&quot;,conf:.8},
{source:&quot;A1&quot;,target:&quot;F8&quot;,type:&quot;arg1&quot;,conf:.8},
{source:&quot;A2&quot;,target:&quot;F2&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A3&quot;,target:&quot;F2&quot;,type:&quot;arg0&quot;,conf:.9},
{source:&quot;A3&quot;,target:&quot;F5&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;A4&quot;,target:&quot;F7&quot;,type:&quot;arg0&quot;,conf:.8},
{source:&quot;A4&quot;,target:&quot;F9&quot;,type:&quot;arg1&quot;,conf:1},
{source:&quot;EL1&quot;,target:&quot;A1&quot;,type:&quot;supports&quot;,conf:.9}
];
var colors={ResearchQuestion:&quot;#fbbf24&quot;,Association:&quot;#a78bfa&quot;,Factor:&quot;#34d399&quot;,EvidenceLine:&quot;#fb7185&quot;};
var edgeColors={motivates:&quot;#60a5fa&quot;,addresses:&quot;#60a5fa&quot;,arg0:&quot;#fbbf24&quot;,arg1:&quot;#fbbf24&quot;,supports:&quot;#34d399&quot;};
var sizes={ResearchQuestion:15,Association:10,Factor:8,EvidenceLine:8};
var W=700,H=500;
var svg=d3.select(&quot;#fylo-graph-viz&quot;).append(&quot;svg&quot;).attr(&quot;viewBox&quot;,&quot;0 0 &quot;+W+&quot; &quot;+H).attr(&quot;width&quot;,&quot;100%&quot;).attr(&quot;height&quot;,&quot;100%&quot;);
var g=svg.append(&quot;g&quot;);
svg.call(d3.zoom().scaleExtent([.5,4]).on(&quot;zoom&quot;,function(e){g.attr(&quot;transform&quot;,e.transform)}));
var link=g.append(&quot;g&quot;).selectAll(&quot;line&quot;).data(links).join(&quot;line&quot;).attr(&quot;stroke&quot;,function(d){return edgeColors[d.type]||&quot;#64748b&quot;}).attr(&quot;stroke-width&quot;,function(d){return d.conf*2}).attr(&quot;stroke-opacity&quot;,.5);
var node=g.append(&quot;g&quot;).selectAll(&quot;g&quot;).data(nodes).join(&quot;g&quot;).call(d3.drag().on(&quot;start&quot;,dragstart).on(&quot;drag&quot;,dragged).on(&quot;end&quot;,dragend));
node.append(&quot;circle&quot;).attr(&quot;r&quot;,function(d){return sizes[d.type]||8}).attr(&quot;fill&quot;,function(d){return colors[d.type]||&quot;#64748b&quot;}).attr(&quot;stroke&quot;,&quot;rgba(255,255,255,0.2)&quot;).attr(&quot;stroke-width&quot;,1.5);
node.append(&quot;text&quot;).text(function(d){return d.title.length&gt;30?d.title.substring(0,30)+&quot;...&quot;:d.title}).attr(&quot;dy&quot;,function(d){return(sizes[d.type]||8)+12}).attr(&quot;text-anchor&quot;,&quot;middle&quot;).attr(&quot;fill&quot;,&quot;#94a3b8&quot;).attr(&quot;font-size&quot;,&quot;7.5px&quot;).attr(&quot;font-family&quot;,&quot;IBM Plex Sans, system-ui, sans-serif&quot;);
var tooltip=d3.select(&quot;#fylo-graph-viz&quot;).append(&quot;div&quot;).style(&quot;position&quot;,&quot;absolute&quot;).style(&quot;display&quot;,&quot;none&quot;).style(&quot;background&quot;,&quot;rgba(30,41,59,.95)&quot;).style(&quot;border&quot;,&quot;1px solid rgba(255,255,255,.1)&quot;).style(&quot;border-radius&quot;,&quot;6px&quot;).style(&quot;padding&quot;,&quot;8px 12px&quot;).style(&quot;font-size&quot;,&quot;11px&quot;).style(&quot;color&quot;,&quot;#e2e8f0&quot;).style(&quot;font-family&quot;,&quot;IBM Plex Sans, system-ui, sans-serif&quot;).style(&quot;pointer-events&quot;,&quot;none&quot;).style(&quot;max-width&quot;,&quot;260px&quot;).style(&quot;z-index&quot;,&quot;10&quot;);
node.on(&quot;mouseover&quot;,function(e,d){tooltip.style(&quot;display&quot;,&quot;block&quot;).html(&quot;&lt;strong style=&apos;color:&quot;+colors[d.type]+&quot;&apos;&gt;&quot;+d.type+&quot;&lt;/strong&gt;&lt;br/&gt;&quot;+d.title)}).on(&quot;mousemove&quot;,function(e){var rect=document.getElementById(&quot;fylo-graph-viz&quot;).getBoundingClientRect();tooltip.style(&quot;left&quot;,(e.clientX-rect.left+12)+&quot;px&quot;).style(&quot;top&quot;,(e.clientY-rect.top-20)+&quot;px&quot;)}).on(&quot;mouseout&quot;,function(){tooltip.style(&quot;display&quot;,&quot;none&quot;)});
var sim=d3.forceSimulation(nodes).force(&quot;link&quot;,d3.forceLink(links).id(function(d){return d.id}).distance(55)).force(&quot;charge&quot;,d3.forceManyBody().strength(-180)).force(&quot;center&quot;,d3.forceCenter(W/2,H/2)).force(&quot;collision&quot;,d3.forceCollide().radius(28));
sim.on(&quot;tick&quot;,function(){link.attr(&quot;x1&quot;,function(d){return d.source.x}).attr(&quot;y1&quot;,function(d){return d.source.y}).attr(&quot;x2&quot;,function(d){return d.target.x}).attr(&quot;y2&quot;,function(d){return d.target.y});node.attr(&quot;transform&quot;,function(d){return&quot;translate(&quot;+d.x+&quot;,&quot;+d.y+&quot;)&quot;})});
function dragstart(e,d){if(!e.active)sim.alphaTarget(.3).restart();d.fx=d.x;d.fy=d.y}
function dragged(e,d){d.fx=e.x;d.fy=e.y}
function dragend(e,d){if(!e.active)sim.alphaTarget(0);d.fx=null;d.fy=null}
var legend=d3.select(&quot;#fylo-graph-viz&quot;).style(&quot;position&quot;,&quot;relative&quot;).append(&quot;div&quot;).style(&quot;position&quot;,&quot;absolute&quot;).style(&quot;bottom&quot;,&quot;8px&quot;).style(&quot;left&quot;,&quot;8px&quot;).style(&quot;display&quot;,&quot;flex&quot;).style(&quot;gap&quot;,&quot;10px&quot;).style(&quot;font-size&quot;,&quot;10px&quot;).style(&quot;font-family&quot;,&quot;IBM Plex Sans, system-ui, sans-serif&quot;);
Object.entries(colors).forEach(function(kv){legend.append(&quot;span&quot;).style(&quot;display&quot;,&quot;flex&quot;).style(&quot;align-items&quot;,&quot;center&quot;).style(&quot;gap&quot;,&quot;4px&quot;).style(&quot;color&quot;,&quot;#94a3b8&quot;).html(&quot;&lt;span style=&apos;display:inline-block;width:8px;height:8px;border-radius:50%;background:&quot;+kv[1]+&quot;&apos;&gt;&lt;/span&gt;&quot;+kv[0])})
})();
&lt;/script&gt;

&lt;p&gt;This is a cropped neighbourhood from FyloVisualizer, a D3.js force-directed graph viewer I built to close that loop. The full viewer renders the complete discourse graph with 167 nodes across 4 types, edges weighted by confidence, hover for metadata and ontology tags, and filtering by semantic role. It loads graph JSON directly from the extraction pipeline output, no manual curation.&lt;/p&gt;

&lt;p&gt;This pattern recurs across my work. The enriched SVG diagrams &lt;a href=&quot;https://striff.io&quot;&gt;striff.io&lt;/a&gt; renders for code architecture diffs serve the same purpose: they translate backend ML quality changes into something a non-technical user can immediately judge. In a neurosymbolic system where most of the engineering is invisible, the visualization layer is part of the production debugging surface.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;em&gt;Muntazir Fadhel builds production AI and ML infrastructure. He is the founder of HADI Technology. &lt;a href=&quot;/downloads/MFadhel_Engagement_Brief.pdf&quot;&gt;Technical Profile&lt;/a&gt; · &lt;a href=&quot;/contact/&quot;&gt;Get in Touch&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
</description>
        <pubDate>Sun, 26 Apr 2026 10:00:00 +0000</pubDate>
        <link>https://mfadhel.com/building-production-neurosymbolic-pipeline-scientific-discourse-graphs/</link>
        <guid isPermaLink="true">https://mfadhel.com/building-production-neurosymbolic-pipeline-scientific-discourse-graphs/</guid>
        
        <category>nlp</category>
        
        <category>knowledge graphs</category>
        
        <category>neurosymbolic</category>
        
        <category>scientific discourse</category>
        
        <category>llm engineering</category>
        
        <category>shex</category>
        
        
      </item>
    
      <item>
        <title>What a decade of ML infrastructure did, and did not, prepare me for with LLMs</title>
        <description>&lt;p&gt;I have worked on ML infrastructure for close to a decade: migrating pipelines into cloud environments, wiring together GPU clusters, making autoscaling behave for workloads that spiked without warning. The models were rarely the hard part. Running them reliably, cheaply and observably was. When the work shifted into LLM systems, serving open models on vLLM and operating agent pipelines under real load, most of that experience carried over. Two incidents taught me where it did not.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;&lt;img src=&quot;/images/hero-green-dashboard.svg&quot; alt=&quot;Every infrastructure metric healthy while the agent&apos;s outputs were malformed&quot; class=&quot;light-border&quot; /&gt;
&lt;em&gt;The infrastructure layer and the model layer fail independently. A dashboard built for the first says nothing about the second.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;the-parser-noticed-before-the-model-layer-did&quot;&gt;The parser noticed before the model layer did&lt;/h2&gt;

&lt;p&gt;On one engagement the model provider shipped a silent update overnight. Nothing in our system changed. The model’s tool-call formatting did, and the first signal we got was the error rate of a downstream parser climbing. Nothing at the model layer reported anything, because from the model layer’s point of view nothing was wrong: requests went out, completions came back, latency was normal, no exception was raised anywhere near the model.&lt;/p&gt;

&lt;p&gt;The errors ran for most of a working day before anyone looked. The alert that finally fired was the parser’s own threshold, set at one in twenty requests failing to parse, and it fired hours after the rate had crossed it because the threshold had been chosen for a parser bug, not for a model change.&lt;/p&gt;

&lt;p&gt;We found it by reading the parser’s failures and working backwards. The fix was small: pin the model to a specific version and upgrade deliberately, with evaluations, the same way we had pinned library versions in every production system for years. The lesson was that a hosted model is a dependency, and an unpinned dependency that changes under you is a class of failure classical ML had already taught me to fear. I had just not filed the model under “dependency”.&lt;/p&gt;

&lt;h2 id=&quot;hours-of-malformed-output-under-a-healthy-dashboard&quot;&gt;Hours of malformed output under a healthy dashboard&lt;/h2&gt;

&lt;p&gt;The second incident was on a project with a good Prometheus setup. GPU utilisation, memory pressure, queue depth, request rate, latency percentiles, error rate, pod restarts: every panel was green. Underneath it an agent pipeline had been producing malformed output for hours, because a prompt assumption stopped holding after a model update, and not one infrastructure metric moved.&lt;/p&gt;

&lt;p&gt;It was noticed when a downstream report came out empty and someone read the raw outputs behind it. By then a few thousand requests had gone through, every one of them accepted by the pipeline as a success.&lt;/p&gt;

&lt;p&gt;That one changed what I monitor. The infrastructure metrics were still right and still necessary. They answered the question they were built for, whether the serving layer was healthy, and it was. The question nobody had instrumented was whether the model was doing what the application needed. Those two questions had been the same question for most of my career, because a classifier that returns a value is either up or it is not. For an agent they are decoupled, and a healthy cluster can run a broken prompt indefinitely.&lt;/p&gt;

&lt;p&gt;What we added, and what I now add by default on any LLM system:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The rate at which structured outputs parse against their expected schema.&lt;/li&gt;
  &lt;li&gt;The rate at which tool calls are well formed and return the result the next step expects.&lt;/li&gt;
  &lt;li&gt;The distribution of response lengths over time, since a shift there is often the first sign a prompt has drifted.&lt;/li&gt;
  &lt;li&gt;Task completion rate, where the task has a definition that can be checked.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These live at the application layer. They need a decision, before the system ships, about what correct means for each use case. And they page. In both incidents, an alert on parse-failure rate would have fired before anyone was looking, and no infrastructure alarm ever would have.&lt;/p&gt;

&lt;h2 id=&quot;failures-now-compound-through-reasoning-not-code&quot;&gt;Failures now compound through reasoning, not code&lt;/h2&gt;

&lt;p&gt;Both incidents have the same shape, and it is the shape that distinguishes LLM systems from the ML systems I ran before. In classical ML, failures are loud. A preprocessing step errors out, a training run crashes, an endpoint returns a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;500&lt;/code&gt;, and the failure leaves stack traces, log lines and metric anomalies you can follow. Even the quiet failures, wrong predictions with no exception, surface in offline evaluation because a classifier’s output can be compared with ground truth mechanically.&lt;/p&gt;

&lt;p&gt;An agent’s failures are quiet by construction. The model generates a plausible but wrong tool call, the tool executes, and the agent keeps reasoning on bad data. Several steps later it produces confident output that is wrong in a way that only makes sense once you trace the full chain. An error in step two of a six-step process biases every step after it, because the model is working from a corrupted context it cannot recognise as corrupted.&lt;/p&gt;

&lt;p&gt;Three mitigations have earned their place:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Structured output schemas enforced at the API boundary, so malformed output is rejected before it enters the reasoning chain rather than validated after the fact.&lt;/li&gt;
  &lt;li&gt;Validation between agent steps, so an intermediate result has to meet basic sanity checks before it is handed on.&lt;/li&gt;
  &lt;li&gt;Full execution traces for any agent whose failures have consequences: every model call, every tool input and output, every intermediate state. Without them, debugging a chain is guesswork.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Human review still sits above all three for high-stakes decisions. The instinct to distrust silent success, built from years of watching pipelines finish cleanly and produce the wrong answer, is the right instinct. It just has to be applied one layer higher than it used to be.&lt;/p&gt;

&lt;h2 id=&quot;evaluation-golden-transcripts-re-run-on-every-prompt-change&quot;&gt;Evaluation: golden transcripts, re-run on every prompt change&lt;/h2&gt;

&lt;p&gt;The received wisdom is continuous evaluation, a representative test set run against the live system on a schedule. I think that is mostly theatre below a certain team size, and I would rather say what I actually do.&lt;/p&gt;

&lt;p&gt;For a small team, evaluation is a handful of golden transcripts, re-run on every prompt change and every model version bump, with the diff read by a person. A prompt is a functional component, and a change to it can alter behaviour as much as a change to a preprocessing function would have. So prompts live in the same repository as the code that calls them, changes are attributed, and the transcripts run before merge, the way unit tests do. Because production usually needs some sampling variability, each transcript is run more than once and the results aggregated rather than treating one sample as the answer.&lt;/p&gt;

&lt;p&gt;On the systems I run today that is about forty transcripts per system, and the diff turns up something worth reading on roughly one prompt change in five.&lt;/p&gt;

&lt;p&gt;That is less than a benchmark suite. It is also honest about what a small team will maintain, and it catches the two failure modes above, because both were a prompt or model change that would have shown up in a re-run transcript before it shipped.&lt;/p&gt;

&lt;h2 id=&quot;the-parts-that-transfer-without-drama&quot;&gt;The parts that transfer without drama&lt;/h2&gt;

&lt;p&gt;Most of the rest of classical ML infrastructure applies to LLM systems with small adjustments, and a short list is enough.&lt;/p&gt;

&lt;p&gt;Latency splits into two measurements. Time to first token is what an interactive user perceives; total completion time is what throughput and cost accounting need. Output length is decided at runtime, so two requests that look identical at ingress can differ by two orders of magnitude in tokens produced. Prefill is parallel and quick; decode is memory-bandwidth bound and runs one token per step. Serving engines batch decode steps across requests (that is what continuous batching in vLLM does), but per-request utilisation still looks nothing like a classifier’s, so autoscaling on GPU utilisation thresholds needs rethinking. The habit of tracking p95 and p99 separately from p50 matters as much as ever; it now applies to first-token time and time per output token as well as to total duration. Sequence models and speech systems had streaming latency metrics long before LLMs, so this is a return to an older discipline rather than a new one.&lt;/p&gt;

&lt;p&gt;Reproducibility has a larger surface. Classical pipelines drifted on code, data and environment. LLM systems also drift on the prompt, the model version, the context-window handling, the tool definitions, the behaviour of the external APIs those tools call, and the sampling parameters. Any of them can change between runs and produce different output without an exception. Pinned environments, versioned data with lineage and logged parameters remain the survival kit; prompt snapshots and model versions join the list of artifacts. The &lt;a href=&quot;https://github.com/hadi-technology/mlops-blueprint&quot;&gt;mlops-blueprint&lt;/a&gt; is my attempt to write that end-to-end discipline down, and the additions for LLM pipelines are small.&lt;/p&gt;

&lt;p&gt;Cost moves up into the application layer, because it is proportional to token volume per request. Output tokens cost more than input tokens because each one is a separate decode step that reads the whole KV cache, which is the memory-bandwidth cost from the latency section showing up on the bill. Three consequences follow. A maximum output length is an infrastructure decision, and setting one that bounds runaway output without truncating valid completions means knowing the response-length distribution per task. Routing simple tasks to a smaller model is a cost lever classical ML never had. And an agent stuck in a retry loop shows up as token volume, not as an error rate, so no infrastructure alarm catches it. For self-hosted models on vLLM the cost shape returns to GPU provisioning, and prefix caching, which reuses the KV cache for a shared system prompt across requests, is the lever that changes the arithmetic.&lt;/p&gt;

&lt;h2 id=&quot;what-this-looks-like-in-what-i-build-now&quot;&gt;What this looks like in what I build now&lt;/h2&gt;

&lt;p&gt;The posture from both incidents, that the model may propose and a program must verify, is the design of &lt;a href=&quot;https://striff.io&quot;&gt;Striff&lt;/a&gt;, the tool I work on today. It reads a repository’s architecture documents, has a language model translate their sentences into rules, and then checks those rules against the parsed code with no model involved. The model never decides whether a rule holds, a silent “could not check” is never recorded as “checked, nothing found”, and every finding names the sentence and the line it came from. That is the parser-error-rate lesson and the green-dashboard lesson, built into the shape of a product rather than added to it afterwards.&lt;/p&gt;

&lt;h2 id=&quot;code-referenced-in-this-post&quot;&gt;Code referenced in this post&lt;/h2&gt;

&lt;div class=&quot;post-badges&quot;&gt;
&lt;a href=&quot;https://github.com/hadi-technology/vllm-mlops&quot;&gt;&lt;img src=&quot;https://img.shields.io/badge/vLLM%20MLOps-vllm--mlops-blue?logo=github&quot; alt=&quot;vllm-mlops&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://github.com/hadi-technology/mlops-blueprint&quot;&gt;&lt;img src=&quot;https://img.shields.io/badge/MLOps%20Pipeline-mlops--blueprint-teal?logo=github&quot; alt=&quot;mlops-blueprint&quot; /&gt;&lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 07 Mar 2026 00:01:00 +0000</pubDate>
        <link>https://mfadhel.com/what-a-decade-of-ml-infrastructure-taught-me-about-llms/</link>
        <guid isPermaLink="true">https://mfadhel.com/what-a-decade-of-ml-infrastructure-taught-me-about-llms/</guid>
        
        <category>llms</category>
        
        <category>mlops</category>
        
        <category>observability</category>
        
        <category>platform engineering</category>
        
        <category>system design</category>
        
        
      </item>
    
      <item>
        <title>Self-Hosting LLMs in Production: The vLLM + KubeAI Stack</title>
        <description>&lt;p&gt;Deploying a large language model is not the hard part. Deploying one in a way that is safe to operate, cost-effective to scale, and straightforward to reason about under load is where most teams run into trouble.&lt;/p&gt;

&lt;p&gt;This walks through an architecture for running self-hosted LLM inference in production, using vLLM as the inference engine and KubeAI for model lifecycle and operational concerns. I have built variants of this stack for teams that could not use a managed API, and the version here is the one I would reach for again.&lt;/p&gt;

&lt;!--more--&gt;
&lt;p&gt;Rather than a step-by-step tutorial, the intent here is to explain the tradeoffs that led to this architecture and where it fits, and where it does not fit, compared to alternatives.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/vllm-kubeai-diagram.svg&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;the-core-operational-problem-with-self-hosted-llm-inference&quot;&gt;The Core Operational Problem with Self-Hosted LLM Inference&lt;/h2&gt;

&lt;p&gt;Running vLLM directly on Kubernetes is not complicated. You deploy a pod with GPU resources, expose a port, and route traffic to it. The problems that emerge are operational:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;How do you handle cold start?&lt;/strong&gt; A vLLM pod serving a 70B model can take several minutes to initialize. Traffic routed to a cold pod will either fail or stack up in ways that are hard to recover from.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;How do you scale from zero without dropping requests during the ramp-up window?&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;How do you maintain KV cache locality across replicas?&lt;/strong&gt; Stateful LLM backends have characteristics that standard round-robin load balancing is not designed for.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;How do you present a stable, OpenAI-compatible API surface that survives backend changes, scaling events, and model version updates?&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Deploying vLLM pods directly answers none of these questions. You end up building an operations layer on top of raw Kubernetes primitives, and that layer tends to grow in complexity over time as each operational problem gets patched individually.&lt;/p&gt;

&lt;p&gt;KubeAI sits one layer above vLLM and handles these concerns natively. The tradeoff is a dependency on an additional platform component. Whether that tradeoff is worth it depends on the operational context, which we will get to.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-kubeai-actually-does&quot;&gt;What KubeAI Actually Does&lt;/h2&gt;

&lt;p&gt;KubeAI introduces a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Model&lt;/code&gt; custom resource that describes what to run rather than how to deploy it:&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;kubeai.org/v1&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Model&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;llama-3.3-70b&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;features&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;TextGeneration&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hf://RedHatAI/Llama-3.3-70B-Instruct-FP8-dynamic&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;engine&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;VLLM&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;--tensor-parallel-size=2&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;--max-model-len=32768&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;--max-num-batched-tokens=8192&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;--kv-cache-dtype=fp8&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;--enable-prefix-caching&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;--gpu-memory-utilization=0.90&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;resourceProfile&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;nvidia-gpu-h100:2&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;minReplicas&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;maxReplicas&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;targetRequests&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;8&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loadBalancing&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;strategy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;PrefixHash&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This runs Llama 3.3 70B Instruct on a single node of eight H100s. At FP8 the weights take about 70 GB, so each replica fits on two GPUs with room left for KV cache, and the node holds up to four replicas. For workloads with long prompts, such as retrieval-heavy assistants, four smaller replicas beat one replica spread across all eight GPUs: they serve requests in parallel, and the FP8 KV cache doubles how many long prompts fit in memory. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;targetRequests: 8&lt;/code&gt; tells KubeAI to add a replica once each one averages eight requests in flight, well below the default of 100, because processing long prompts saturates a replica long before that. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;minReplicas: 1&lt;/code&gt; keeps one replica warm, since a cold 70B start takes minutes.&lt;/p&gt;

&lt;p&gt;The model name &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;llama-3.3-70b&lt;/code&gt; becomes the identifier used in OpenAI-compatible requests. KubeAI owns the rest: pulling the model, caching it, launching vLLM backend pods, buffering requests during initialization, and routing traffic once the backend is ready.&lt;/p&gt;

&lt;p&gt;The request flow through the stack:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Traffic arrives at the KubeAI OpenAI-compatible proxy&lt;/li&gt;
  &lt;li&gt;KubeAI selects or spins up a backend for the target model&lt;/li&gt;
  &lt;li&gt;Requests are queued while the backend initializes, rather than being dropped or returning errors&lt;/li&gt;
  &lt;li&gt;The request is forwarded to vLLM&lt;/li&gt;
  &lt;li&gt;Responses stream back through the proxy&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The queuing behavior is the most practically important property KubeAI provides. A new vLLM pod is cold whenever KubeAI adds a replica under load, rolls out a model update, replaces a crashed pod, or starts a model from zero, and each start takes minutes. Without buffering, the requests that arrive in that window fail or pile up in ways that are hard to recover from. With it, they wait until the pod is ready.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;keeping-conversations-on-the-same-replica&quot;&gt;Keeping Conversations on the Same Replica&lt;/h2&gt;

&lt;p&gt;LLM requests are stateless. vLLM keeps no record of a conversation, so on every turn the client sends everything again: the system prompt, any retrieved documents, the earlier questions and answers, and the new question. Turn three of a conversation can easily resend 25,000 tokens, most of which the model already read on turn two.&lt;/p&gt;

&lt;p&gt;Reading those tokens is the expensive part. For every token in the prompt, the model computes intermediate values called keys and values, and vLLM holds them in GPU memory in the KV cache. With prefix caching enabled, vLLM keeps them after a request finishes. If a later request starts with exactly the same tokens, vLLM reuses that work and only processes what is new. For a follow-up question, that can cut time to first token from over a second to a fraction of one.&lt;/p&gt;

&lt;p&gt;Each replica, however, has its own KV cache, and that cache is what makes the backends stateful even though the requests are not. Behind a standard Kubernetes Service, requests land on an essentially random pod, so the turns of one conversation scatter across replicas and the cache hit rate falls as you add replicas. Every answer is still correct. It is just slower and more expensive than it needs to be.&lt;/p&gt;

&lt;p&gt;KubeAI handles this with its &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PrefixHash&lt;/code&gt; load balancing strategy, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;loadBalancing&lt;/code&gt; block in the Model above. The proxy hashes the first 100 characters of the first user message onto a consistent hash ring, where each replica holds 256 positions. Every turn of a conversation shares that first message, so every turn lands on the same replica. If that replica is running above 125% of the average load, the request moves to the next replica on the ring instead of queueing. When KubeAI adds or removes a replica, only the conversations near that replica’s positions move, and everyone else keeps their cache. The default strategy, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LeastLoad&lt;/code&gt;, balances load but ignores the cache, so this has to be switched on.&lt;/p&gt;

&lt;p&gt;KubeAI predicts where a conversation’s cache lives without ever looking inside vLLM, so the routing only works if the application builds its prompts with it in mind:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Put shared instructions in the system message, which KubeAI skips when hashing, and start the first user message with the user’s actual question. If every first user message opens with the same template text, every request hashes to the same replica.&lt;/li&gt;
  &lt;li&gt;Keep earlier messages identical from turn to turn and add newly retrieved documents at the end. The cache only matches from the start of the prompt, so rebuilding or reordering earlier content throws the match away.&lt;/li&gt;
  &lt;li&gt;Keep timestamps and other per-request values out of the start of the prompt for the same reason.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;precision-and-gpu-sizing-decisions-that-compound&quot;&gt;Precision and GPU Sizing: Decisions That Compound&lt;/h2&gt;

&lt;p&gt;For a 70B model, these are not configuration details. They are architectural decisions that affect cost, latency, and reliability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Precision.&lt;/strong&gt; BF16 is the safe default on A100 and H100-class hardware, and it is the format most open models ship in. FP16 also works and the practical difference in most serving scenarios is small, but its narrower range can overflow on models trained in BF16, which matters when debugging unexpected inference behavior. Below 16 bits, FP8 is the first thing to try on H100-class GPUs: it halves weight memory with little accuracy loss on most models. 4-bit quantization goes further (a 70B model at INT4 fits on one H100, where FP16 needs two to four once you leave room for KV cache), but every step down introduces accuracy tradeoffs that need to be validated carefully against your specific use case before deploying to production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GPU sizing.&lt;/strong&gt; The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resourceProfile&lt;/code&gt; field in the Model spec makes GPU requirements explicit and decoupled from model configuration. In direct vLLM deployments, GPU sizing often ends up embedded in Deployment specs alongside model configuration, which makes it easy to change one without reviewing the other. Keeping the GPU profile as a named, versioned resource makes changes reviewable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Batching.&lt;/strong&gt; The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--max-num-batched-tokens&lt;/code&gt; parameter controls continuous batching behavior, which is one of vLLM’s core performance advantages over naive request-by-request inference. Getting this right requires understanding the request latency profile you are targeting and the typical prompt/completion length distribution for your workload. Too conservative and you leave GPU utilization on the table. Too aggressive and tail latency suffers.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;when-this-architecture-makes-sense-and-when-it-does-not&quot;&gt;When This Architecture Makes Sense and When It Does Not&lt;/h2&gt;

&lt;p&gt;This stack is a good fit when:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;You need to run self-hosted inference for data residency, cost, or customization reasons and cannot use a managed API provider&lt;/li&gt;
  &lt;li&gt;You are serving multiple models that need independent lifecycle management, where model A and model B should be able to update, scale, and fail independently&lt;/li&gt;
  &lt;li&gt;You serve several models that each see only occasional traffic, so they can scale to zero and share a pool of GPUs without dropping the requests that arrive while one starts up&lt;/li&gt;
  &lt;li&gt;You want a stable OpenAI-compatible API surface that allows client code to be model-agnostic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is not the right fit when:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A managed API provider (OpenAI, Anthropic, Vertex AI) meets your requirements, since managed endpoints abstract away all of this complexity and the operational cost is lower at moderate scale&lt;/li&gt;
  &lt;li&gt;You are prototyping or running experiments where operational overhead is more costly than GPU spend&lt;/li&gt;
  &lt;li&gt;You are serving a model that fits comfortably in CPU memory or on a single GPU with no scaling requirements, in which case deploying KubeAI adds unnecessary overhead&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In client work, the decision to go self-hosted rather than managed typically comes down to one of three things: a hard data residency requirement, a model that is not available through managed APIs, or a cost calculation at high enough inference volume that managed API pricing becomes prohibitive. My default for teams under roughly ten engineers is to stay on a managed API until one of those reasons forces the move, because the operational surface here is larger than it looks on the diagram.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exposing-the-api-and-multi-tenant-considerations&quot;&gt;Exposing the API and Multi-Tenant Considerations&lt;/h2&gt;

&lt;p&gt;The KubeAI service provides an OpenAI-compatible API internally at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://kubeai/openai/v1&lt;/code&gt;. Exposing it externally involves a standard Kubernetes Ingress:&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;networking.k8s.io/v1&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Ingress&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;kubeai-ingress&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;annotations&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;nginx.ingress.kubernetes.io/proxy-buffering&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;off&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;nginx.ingress.kubernetes.io/proxy-read-timeout&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;600&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;nginx.ingress.kubernetes.io/proxy-send-timeout&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;600&quot;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;llm.example.com&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;http&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/openai&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;pathType&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Prefix&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;backend&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
              &lt;span class=&quot;na&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;kubeai&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
                  &lt;span class=&quot;na&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;80&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The annotations assume ingress-nginx. They turn off response buffering so streamed tokens reach the client as they are generated, and raise the timeouts so long answers are not cut off at the default of 60 seconds.&lt;/p&gt;

&lt;p&gt;In multi-tenant deployments, which is the typical case for teams like &lt;a href=&quot;https://www.joinable.ai&quot;&gt;Joinable&lt;/a&gt; where the inference infrastructure serves multiple downstream applications, this is where authentication and per-tenant rate limiting need to be layered in. KubeAI does not provide tenant isolation natively. That sits in the API gateway layer in front of it. The clean separation of concerns here is an advantage: the inference infrastructure does not need to carry application-level concerns about who is calling it.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;observability-what-to-instrument-and-why&quot;&gt;Observability: What to Instrument and Why&lt;/h2&gt;

&lt;p&gt;A self-hosted LLM deployment without proper observability is one incident away from an extended outage. The metrics that matter most in practice are not the generic Kubernetes resource metrics. They are inference-specific signals:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Token throughput.&lt;/strong&gt; Are you fully utilizing the GPU’s batching capacity, or are requests being processed one at a time? This is the difference between a deployment that is cost-efficient and one that is burning GPU budget without proportional output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Queue depth.&lt;/strong&gt; How many requests are waiting for a backend? Sustained queue depth is an early warning of capacity exhaustion, visible well before latency metrics deteriorate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time-to-first-token (TTFT) and inter-token latency.&lt;/strong&gt; These have different sensitivity profiles for different applications. A chatbot application cares more about TTFT. A batch processing pipeline cares more about total throughput. Knowing which one matters for your use case determines where to optimize.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cold start frequency.&lt;/strong&gt; If you have scale-from-zero enabled, tracking how often pods are spinning up from zero tells you whether the cost savings from idle scale-down are worth the latency impact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prefix cache hit rate.&lt;/strong&gt; The share of prompt tokens served from the KV cache, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vllm:prefix_cache_hits&lt;/code&gt; divided by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vllm:prefix_cache_queries&lt;/code&gt;. A drop after scaling out, or a rate that stays low with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PrefixHash&lt;/code&gt; enabled, usually means the application is changing the start of its prompts between turns.&lt;/p&gt;

&lt;p&gt;The vLLM &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/metrics&lt;/code&gt; endpoint exposes Prometheus-compatible metrics. The KubeAI Helm chart ships a PodMonitor for the vLLM pods (off by default, enabled with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;metrics.prometheusOperator.vLLMPodMonitor.enabled&lt;/code&gt;) that wires those into Prometheus scraping. From there, the standard observability stack (Prometheus, Grafana) gives you the visibility you need.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;operational-cost-as-a-design-input&quot;&gt;Operational Cost as a Design Input&lt;/h2&gt;

&lt;p&gt;One framing that tends to change how these decisions get made: GPU time is expensive, and most teams underestimate how much of their GPU spend goes to idle capacity rather than actual inference. I have seen teams discover that two-thirds of their GPU budget was burning on pods sitting idle between traffic bursts.&lt;/p&gt;

&lt;p&gt;For the main interactive model, the answer is usually to keep at least one replica warm, since nobody accepts a multi-minute wait on the first question of the morning. If traffic follows the workday, a scheduled job that raises &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;minReplicas&lt;/code&gt; before people arrive and lowers it at night captures most of the savings. Scale-from-zero pays off elsewhere: in the long tail of occasionally used models, such as team fine-tunes or models under evaluation, and in batch work where nobody is waiting on the answer. Either way, the savings are only real if the freed GPUs run other work or the node itself is removed. On hardware you own, an idle GPU costs the same whether a replica is running on it or not.&lt;/p&gt;

&lt;p&gt;The precision decision is also a cost decision. A model that can run at INT4 rather than FP16 may fit on a smaller GPU class, which changes the instance pricing significantly. Validating quantization accuracy early in the project is worth the investment.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;closing-thoughts&quot;&gt;Closing Thoughts&lt;/h2&gt;

&lt;p&gt;The combination of vLLM and KubeAI is not the simplest possible way to self-host an LLM. It is the simplest way to self-host an LLM that is safe to operate at production scale, where cold starts, traffic spikes, model updates, and cost management are daily concerns rather than edge cases.&lt;/p&gt;

&lt;p&gt;Code: &lt;a href=&quot;https://github.com/hadi-technology/vllm-mlops&quot;&gt;github.com/hadi-technology/vllm-mlops&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;em&gt;Muntazir Fadhel builds production AI and ML infrastructure. He is the founder of HADI Technology. &lt;a href=&quot;/downloads/MFadhel_Engagement_Brief.pdf&quot;&gt;Technical Profile&lt;/a&gt; · &lt;a href=&quot;/contact/&quot;&gt;Get in Touch&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 16 Dec 2024 15:04:23 +0000</pubDate>
        <link>https://mfadhel.com/vllm-kubeai/</link>
        <guid isPermaLink="true">https://mfadhel.com/vllm-kubeai/</guid>
        
        <category>llmops</category>
        
        <category>mlops</category>
        
        <category>kubernetes</category>
        
        <category>vllm</category>
        
        <category>model serving</category>
        
        
      </item>
    
      <item>
        <title>Designing a Production MLOps Pipeline: The Decisions That Actually Determine Reliability</title>
        <description>&lt;p&gt;Across client engagements at HADI Technology, one pattern shows up consistently: teams invest heavily in model development and then ship the surrounding infrastructure as an afterthought. The ML code works. The pipeline that runs it in production slowly becomes a liability.&lt;/p&gt;

&lt;p&gt;This post distills a reference architecture we built to address that. The context is a pipeline for categorizing and analyzing GitHub pull requests using a PyTorch autoencoder, developed as a reusable blueprint based on what we have seen fail repeatedly in production ML systems. The intent was not to solve a difficult modeling problem but to demonstrate the infrastructure patterns that determine whether a system holds up over time. The full implementation is available at &lt;a href=&quot;https://github.com/hadi-technology/mlops-blueprint&quot;&gt;github.com/hadi-technology/mlops-blueprint&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;These same patterns – reproducible pipelines, blue/green rollouts, single-build artifacts, and Vault-based secret management – later became the foundation for &lt;a href=&quot;https://striff.io&quot;&gt;striff.io&lt;/a&gt;’s production ML system. The Striff service runs on the same blueprint: one built image, Argo CD applying the manifests, and secrets from Vault.&lt;/p&gt;

&lt;div style=&quot;border:1px solid rgba(15,23,42,0.08);border-radius:12px;padding:14px 18px;margin:16px 0;background:rgba(255,255,255,0.6);&quot;&gt;
&lt;p style=&quot;margin:0 0 8px 0;font-size:0.75rem;font-weight:700;letter-spacing:0.08em;text-transform:uppercase;color:#6b7280;&quot;&gt;Relevant Repos&lt;/p&gt;
&lt;div style=&quot;display:flex;flex-wrap:wrap;gap:6px;align-items:center;&quot;&gt;
&lt;a href=&quot;https://github.com/hadi-technology/mlops-blueprint&quot;&gt;&lt;img src=&quot;https://img.shields.io/badge/MLOps%20Pipeline-mlops--blueprint-teal?logo=github&quot; alt=&quot;mlops-blueprint&quot; /&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!--more--&gt;

&lt;p&gt;&lt;img src=&quot;/images/mlops-pipeline-diagram.svg&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;why-anomaly-detection-before-classification&quot;&gt;Why Anomaly Detection Before Classification&lt;/h2&gt;

&lt;p&gt;When labeled data is sparse, and it almost always is early in a project, reaching for a supervised classifier tends to produce a model that looks better in evaluation than it actually is. With pull request data, there is no reliable ground truth for “risky” or “anomalous” changes, so supervised classification would have required either expensive labeling or synthetic labels that introduce their own assumptions.&lt;/p&gt;

&lt;p&gt;An autoencoder trained to reconstruct normal patterns lets the anomaly threshold emerge from reconstruction error rather than from an arbitrarily defined label. This framing also defers the harder modeling question (what exactly constitutes a problematic PR?) until there is enough operational data to answer it meaningfully. It is a more defensible starting point when the problem is still being understood.&lt;/p&gt;

&lt;p&gt;The pipeline feeds the model PR metadata: additions, deletions, changed file counts, labels, author association, and related signals. From there, the question of whether a given PR is an outlier relative to normal project patterns becomes tractable without labeled training data.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;secret-management-why-vault-and-not-environment-files&quot;&gt;Secret Management: Why Vault and Not Environment Files&lt;/h2&gt;

&lt;p&gt;Every pipeline stage needs credentials: GitHub tokens for data ingestion, MongoDB URIs for storage, object storage keys for features, and MLflow credentials for experiment tracking. The temptation in these situations is to reach for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env&lt;/code&gt; files or inject secrets as CI environment variables.&lt;/p&gt;

&lt;p&gt;The problem with that approach is not just security. It is operational fragility. Secrets baked into environment files or injected through CI variables are painful to rotate, difficult to audit, and tend to proliferate across container images and build logs in ways that are hard to fully trace. In client environments like those at SkanAI, where infrastructure serves major financial institutions, this kind of loose secret handling is simply not acceptable.&lt;/p&gt;

&lt;p&gt;We standardized on Vault for all secrets. Each container receives only three environment variables at startup: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VAULT_ADDR&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VAULT_ROLE&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VAULT_SECRET_PATH&lt;/code&gt;. Actual credentials are fetched at runtime using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hvac&lt;/code&gt; Python client. Nothing sensitive ever lands in Git or in a container layer.&lt;/p&gt;

&lt;p&gt;The architectural consequence is that secret rotation requires no code changes and no image rebuilds. Rotating a GitHub token or MongoDB credential is a Vault operation, not a deployment event. Over time, this compounds.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;preventing-environment-drift-the-structural-choice&quot;&gt;Preventing Environment Drift: The Structural Choice&lt;/h2&gt;

&lt;p&gt;Staging and production diverge in subtle ways when there is no deliberate architectural constraint preventing it. A one-off config change made directly to the staging cluster, a dependency pinned differently, a Kubernetes resource limit adjusted during debugging: over weeks and months, these accumulate into a staging environment that does not meaningfully predict production behavior.&lt;/p&gt;

&lt;p&gt;We address this structurally rather than procedurally across most client engagements. The pattern is two separate Kubernetes clusters (one for staging, one for production), sharing a single set of base Kubernetes manifests. Argo CD in each cluster points to the same base manifests from different Git branches: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;staging&lt;/code&gt; tracks the staging branch, production tracks &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt;. Promotion is a merge, not a redeployment.&lt;/p&gt;

&lt;p&gt;The key property this creates is that you cannot accidentally promote without going through version control. There is no manual &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;kubectl apply&lt;/code&gt; path to production. Drift has to be introduced deliberately, through code, which means it is visible and reviewable.&lt;/p&gt;

&lt;p&gt;This is worth distinguishing from overlay-heavy setups where staging and production have separate Kustomize overlays that diverge over time. Overlays are useful for environment-specific configuration, but they can become a source of drift if the base is not kept genuinely shared. The goal is that staging and production are running the same manifests with minimal parameterized differences, not parallel configurations that happen to look similar.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;single-build-artifact-strategy&quot;&gt;Single-Build Artifact Strategy&lt;/h2&gt;

&lt;p&gt;Building separate container images for staging and production is one of those practices that feels harmless until it causes a failure that takes two days to trace. The issue is not that the builds are intentionally different. It is that dependency resolution, base image layers, and build context can vary in ways that are difficult to detect until something breaks in production that worked in staging.&lt;/p&gt;

&lt;p&gt;The pipeline uses a single-build approach across all stages. An image is built once, tested ephemerally against the same image that was just built, deployed to staging, and after validation promoted to production using the same digest. There is no second build.&lt;/p&gt;

&lt;p&gt;The CI workflow pattern is consistent across all stages:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Build the image on code change&lt;/li&gt;
  &lt;li&gt;Run ephemeral container tests against the freshly built image&lt;/li&gt;
  &lt;li&gt;Deploy to staging&lt;/li&gt;
  &lt;li&gt;Promote to production via branch merge, using the same image tag&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The practical effect is that if something passes staging, it will not fail in production due to a build artifact difference. The number of production incidents that trace back to “worked in staging” is high enough that this warrants an architectural constraint rather than a best-effort practice.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bluegreen-rollouts-for-model-serving&quot;&gt;Blue/Green Rollouts for Model Serving&lt;/h2&gt;

&lt;p&gt;Model updates are different from regular service deployments in one important way: the rollout risk is asymmetric. A new model that scores poorly under production traffic has already affected real users by the time it is caught. Rolling back after the fact is costlier than never having routed traffic to it in the first place.&lt;/p&gt;

&lt;p&gt;We use Argo Rollouts with a blue/green strategy for the inference serving component. New model versions are deployed alongside the active version. Traffic continues flowing to the current version while the new version handles requests through a preview service. Load tests run against the preview, and only after those pass does traffic cut over. Rollback is instantaneous because the previous version is still running.&lt;/p&gt;

&lt;p&gt;The cost of this approach is resource usage: you are briefly running two full serving stacks. For a production system handling real traffic at scale, this is an acceptable trade. For a smaller experiment, it might feel like over-engineering. It is better to practice these rollout patterns on small systems than to discover their importance for the first time on a system that cannot afford downtime.&lt;/p&gt;

&lt;p&gt;The alternative, a rolling update that replaces pods incrementally, is fine for stateless services where any request can be handled by any pod. It is less appropriate for model serving, where the inference behavior changes discretely between versions and you want a clear before/after boundary rather than a window where both old and new model versions are simultaneously handling traffic.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;data-processing-and-experiment-tracking&quot;&gt;Data Processing and Experiment Tracking&lt;/h2&gt;

&lt;p&gt;Spark is often positioned as a big data tool, which leads teams to dismiss it for smaller workloads. The more useful framing is that Spark handles large-scale feature transformations reliably and without requiring you to manage memory carefully in a single Python process. For preprocessing PR data at any meaningful scale, a single-process approach will eventually hit a wall.&lt;/p&gt;

&lt;p&gt;MLflow’s value in this context is not so much in the model training itself. It is in the operational discipline it enforces. Every training run is logged. Metrics are tracked. Model artifacts are versioned. When a new run underperforms, there is a clear comparison point rather than a vague memory of what parameters were used last time.&lt;/p&gt;

&lt;p&gt;Locust load-tests the inference endpoint before rollout, which bridges the gap between offline model evaluation and online system behavior. A model that scores well on reconstruction error but causes the serving container to OOM under concurrent requests is still a broken deployment. Load testing before promotion catches this class of failure.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;cost-and-operational-risk-as-design-inputs&quot;&gt;Cost and Operational Risk as Design Inputs&lt;/h2&gt;

&lt;p&gt;Something absent from most MLOps writing is an honest discussion of how cost and operational risk should shape architectural decisions from the start, not as afterthoughts.&lt;/p&gt;

&lt;p&gt;The single-build approach reduces rollout risk. The shared manifest base reduces the cost of maintaining two environments. The Vault integration reduces the operational overhead of secret rotation. Blue/green rollouts reduce the cost of a bad model deployment. These are not independent technical choices. They are a coordinated set of decisions that collectively reduce the total cost of operating the system over time.&lt;/p&gt;

&lt;p&gt;In client work through HADI Technology, the framing we bring to these decisions is: what is the ongoing cost of operating this the wrong way? The answer usually justifies investing in the right patterns upfront. A secret management scheme that requires image rebuilds to rotate credentials looks cheap initially and expensive at the worst possible moment.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;closing-thoughts&quot;&gt;Closing Thoughts&lt;/h2&gt;

&lt;p&gt;The PR categorization experiment is a relatively small ML use case. The infrastructure around it is not. That gap is intentional: the value of working through these design decisions on a contained problem is that the patterns are ready when the problem gets larger. They were. The same decisions described here – single-build artifacts, shared manifests, blue/green rollouts, Vault – now run in production at &lt;a href=&quot;https://striff.io&quot;&gt;striff.io&lt;/a&gt; at higher volume and with additional complexity (Kafka staging, Triton inference, GNN scoring) layered on top.&lt;/p&gt;

&lt;p&gt;Promotion to production is a single merge. Secret rotation does not require rebuilds. New models can be shipped without downtime. These properties did not emerge from the tools. They came from the decisions made before the tools were chosen.&lt;/p&gt;

&lt;p&gt;The full implementation is at &lt;a href=&quot;https://github.com/hadi-technology/mlops-blueprint&quot;&gt;github.com/hadi-technology/mlops-blueprint&lt;/a&gt;.&lt;/p&gt;
</description>
        <pubDate>Tue, 09 Jan 2024 15:04:23 +0000</pubDate>
        <link>https://mfadhel.com/mlops-blueprint/</link>
        <guid isPermaLink="true">https://mfadhel.com/mlops-blueprint/</guid>
        
        <category>mlops</category>
        
        <category>gitops</category>
        
        <category>kubernetes</category>
        
        <category>machine learning</category>
        
        <category>system design</category>
        
        
      </item>
    
      <item>
        <title>Deploy A Production-Ready E-Commerce Solution on AWS with CloudFormation</title>
        <description>
</description>
        <pubDate>Fri, 11 Sep 2020 15:04:23 +0000</pubDate>
        <link>https://mfadhel.com/scalable-prestashop/</link>
        <guid isPermaLink="true">https://mfadhel.com/scalable-prestashop/</guid>
        
        <category>aws</category>
        
        <category>ecommerce</category>
        
        <category>cloudformation</category>
        
        <category>scalability</category>
        
        
      </item>
    
      <item>
        <title>3 Common Misunderstandings of Inter-Service Communication in MicroServices</title>
        <description>&lt;p&gt;Think back to the last time you worked in a distributed system, did you consider using something &lt;strong&gt;other&lt;/strong&gt; than RESTful HTTP calls as the method of communication &lt;em&gt;between components in this system&lt;/em&gt;?
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;In the world of microservices, the problem of inter-service communication has given rise to two main solutions. The first solution is based on the use of
&lt;a href=&quot;https://en.wikipedia.org/wiki/Representational_state_transfer#Applied_to_Web_services&quot; target=&quot;_blank&quot;&gt;RESTful&lt;/a&gt; HTTP calls, while the other solution revolves around the use of
&lt;a href=&quot;https://en.wikipedia.org/wiki/Message_queue&quot; target=&quot;_blank&quot;&gt;message queues&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As is typically the case when making such design decisions, the right decision is made based on a firm understanding of your &lt;strong&gt;requirements&lt;/strong&gt; and the &lt;strong&gt;trade-offs&lt;/strong&gt; involved in either approach. In this post, we’ll try to improve our understanding of these trade-offs by analyzing some widely held misconceptions that are often given in justifying one approach over the other.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/1536697037-consul-dynamic-infrastructure.svg&quot; alt=&quot;cd_img&quot; /&gt;&lt;/p&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#overview&quot; id=&quot;markdown-toc-overview&quot;&gt;Overview&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#message-queues-add-additional-cost&quot; id=&quot;markdown-toc-message-queues-add-additional-cost&quot;&gt;Message Queues Add Additional Cost&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#message-queues-introduce-a-single-point-of-failure-spof&quot; id=&quot;markdown-toc-message-queues-introduce-a-single-point-of-failure-spof&quot;&gt;Message Queues Introduce a Single point of failure (SPOF)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#unlike-http-calls-messaging-is-asynchronous&quot; id=&quot;markdown-toc-unlike-http-calls-messaging-is-asynchronous&quot;&gt;Unlike HTTP Calls, Messaging is Asynchronous&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#do-you-agree&quot; id=&quot;markdown-toc-do-you-agree&quot;&gt;Do you Agree?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;Ideally, services are self contained in a distributed system and don’t need to rely on each other to do their job. This is one of the many parallels between services in a MicroServices architecture and &lt;a href=&quot;http://mfadhel.com/lost-oop/#objects-are-intelligent-and-self-contained&quot; target=&quot;_blank&quot;&gt;objects&lt;/a&gt; in an object oriented system. However, as is commonly found in both domains, such a thing is not possible 100% of the time. As a result, services need a way to communicate with each other.&lt;/p&gt;

&lt;p&gt;To introduce this discussion of inter-service communication approaches, let’s first define some key concepts:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Microservices&lt;/strong&gt;: both a software development method and architectural style for that focuses on building sophisticated software systems as a collection of loosely coupled and highly maintainable single-function modules with well-defined interfaces and operations. Our discussion revolves around the communication between services in such systems.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;REST&lt;/strong&gt;: An architectural design patten for APIs that revolves around the concept of resources. For our discussion, it is sufficient to understand that communication in a REST architecture is typically implemented via HTTP protocols where senders &lt;strong&gt;directly&lt;/strong&gt; invoke consumers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Message Queue&lt;/strong&gt;: An asynchronous, &lt;strong&gt;decoupled&lt;/strong&gt; form of inter-service communication in which senders of data place messages in a message queue until they are processed and deleted by receiving services.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the last few years, microservices have witnessed a tremendous growth in popularity as organizations increasingly transform
their monolithic applications into microservices. However, it is interesting to see that most introductory articles, tutorials, and
guides on the subject of microservices implement inter-service communication using synchronous RESTful communication patterns.&lt;/p&gt;

&lt;figure class=&quot;image&quot;&gt;
  &lt;img src=&quot;/images/interest_micro.png&quot; alt=&quot;Google trends chart for interest over time for the search term &apos;microservices&apos;.&quot; /&gt;
  &lt;figcaption&gt;Google trends chart for interest over time for the search term &apos;microservices&apos;.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;This is not surprising, as this communication mechanism is easiest to adopt by clients due to its simplicity and extensive support in the form of libraries in every programming language. Not to mention, RESTful systems can be documented in some pretty
&lt;a href=&quot;http://mfadhel.com/API_Tables/#api-tables&quot; target=&quot;_blank&quot;&gt;intuitive ways&lt;/a&gt; due to its reliance on the concept of resources. However, as Martin Thompson puts it,&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;“Synchronous communication is the crystal meth of distributed software”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and is generally overused in most microservices implementations and data pipelines.&lt;/p&gt;

&lt;p&gt;Although less formal support is natively provided for security, caching, and documentation in message queues, they have their own set of
advantages over RESTful HTTP calls. Not only do message queues decouple senders from receivers, but they also make systems much more
fault tolerant. That is, messages can be persisted in the queue even when individual services go down. These services can then resume
reading messages from the queue when they are back online.&lt;/p&gt;

&lt;p&gt;At the end of the day, there are usually good reasons to use both mechanisms in a distributed system.
In this post however, I want to &lt;strong&gt;focus on some of the wrong reasons&lt;/strong&gt; commonly given to use one communication mechanism over the other.&lt;/p&gt;

&lt;h2 id=&quot;message-queues-add-additional-cost&quot;&gt;Message Queues Add Additional Cost&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;“The cost of the message queue infrastructure to persist messages introduces significantly increased costs to the system.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Firstly, HTTP communication would typically be routed through
a load balancer in the absence of a message queue, which would incur some cost anyways although it may not be as significant.&lt;/p&gt;

&lt;p&gt;Secondly, message queues typically operate over much &lt;em&gt;lighter weight&lt;/em&gt; protocols than HTTP, which increases the effectiveness of your
infrastructure and lowers costs incurred as a result. When two services are experiencing 
a large amount of traffic between each other, the overhead of creating the TCP connection and negotiating SSL/TLS for all the 
requests sent between these two services is extremely large since HTTP cannot keep a connection open.&lt;/p&gt;

&lt;p&gt;On the other hand, protocols like &lt;a href=&quot;https://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol&quot; target=&quot;_blank&quot;&gt;Advanced Message Queuing Protocol&lt;/a&gt;
(AMQP) over which many message queue technologies are based on create a connection at the start
and persist it. They keep messages flowing between service on top of the TCP connection, and so the TCP and SSL/TLS cost is only paid
once. The protocol minimizes the number of bytes that flow over the wire, and is ideally suited for systems that need to exchange
a high volume of small messages.&lt;/p&gt;

&lt;figure class=&quot;image&quot;&gt;
  &lt;img src=&quot;/images/camqp.png&quot; alt=&quot;High level overview of the AMQP protocol.&quot; /&gt;
  &lt;figcaption&gt;High level overview of the AMQP protocol.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Lastly, the requirement of fault tolerance and failure in your systems needs to be clarified for this statement regarding cost to be true.
If your system has higher tolerance levels for failed transmissions, than using message queues is more costly. 
However, if your system has a low tolerance for message deliveries and failed transmissions, then you must select one
of the following two options:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Develop and manage logic to handle failed communications between services &lt;strong&gt;inside&lt;/strong&gt; the services themselves.&lt;/li&gt;
  &lt;li&gt;Use a message queue&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Option &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; would typically involve the use of additional infrastructure components such as a database/caching system.
Additionally, the level of complexity and sophistication involved in developing resilient and robust inter-services data 
transmission mechanisms would far outweigh the cost of using a ready-made tool designed to solve exactly that problem.
In this scenario, more cost would be incurred to an organization that chooses not to use a message queue, and so this statement 
would not be true in this case.&lt;/p&gt;

&lt;h2 id=&quot;message-queues-introduce-a-single-point-of-failure-spof&quot;&gt;Message Queues Introduce a Single point of failure (SPOF)&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Message queues introduce an entirely new piece of infrastructure to your architecture. As a result of being solely responsible for enabling communication between services, such a component introduces a massive SPOF.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Minus any extra architectural concerns to make them Highly Available (HA), message queues are a SPOF. However, they certainly
&lt;strong&gt;do not introduce&lt;/strong&gt; a SPOF to any existing microservices implementation.
Mechanisms like load balancers and API Gateways are SPOFs that are considered integral to any microservices architecture. They too,
like message queues, must be designed to be HA any microservices implementation.&lt;/p&gt;

&lt;figure class=&quot;image&quot;&gt;
  &lt;img src=&quot;/images/microservices_diag.png&quot; alt=&quot;Like a message queue, an API gateway needs to be HA to avoid being a SPOF.&quot; /&gt;
  &lt;figcaption&gt;Like a message queue, an API gateway needs to be HA to avoid being a SPOF.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;One disadvantage of RESTful HTTP calls however is that services must receive communications directly from senders, which represents a
SPOF. If the receiving service becomes 
unavailable for any reason, the system will lose any transmitted data and essentially fail in the sense of being unable to move forward
with the process.&lt;/p&gt;

&lt;p&gt;The advantage of message queues here lies in its ability to handle downtime for individual services. That is to say, the queue can
still keep the messages transmitted to it by a sender service until the receiving service is available again and able to consume them. 
Moreover, we would only have to worry about making our message queue highly available as opposed to every single service within our 
system.&lt;/p&gt;

&lt;h2 id=&quot;unlike-http-calls-messaging-is-asynchronous&quot;&gt;Unlike HTTP Calls, Messaging is Asynchronous&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Unlike AMQP, HTTP is a synchronous protocol which prevents services that use it from communicating in an asynchronous way”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;HTTP is certainly a synchronous protocol, but the terms synchronous and asynchronous have different connotations depending on which domain it is used in, making over oversimplifications such as these all too common. Lets analyze it at three levels:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1 - Input/Output Level&lt;/strong&gt;:  At this level, asynchronous means that requests made to other services do not block the main executing
thread until the service has responded. This allows the thread to complete other tasks in the meantime, and increases the efficiency
of your CPU by allowing you to serve more requests.&lt;/p&gt;

&lt;figure class=&quot;image&quot;&gt;
  &lt;img src=&quot;/images/1_Y41dOkntUbR3I4UCJBx9Xg.png&quot; alt=&quot;RESTFul HTTP calls can be implemented in both a synchronous and asynchronous fashion at an IO level.&quot; /&gt;
  &lt;figcaption&gt;RESTFul HTTP calls can be implemented in both a synchronous and asynchronous fashion at an IO level.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;This level of asynchronization can be implemented in both RESTful calls and 
message queues, which makes the statement above false. I’ve illustrated an example below using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CompletableFuture&lt;/code&gt; mechanism introduced in Java 8 to make an asynchronous HTTP call 
to an API. It’s asynchronous because the request completes in a separate thread and does not block the main thread.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CompletableFuture&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;HttpClient&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;newHttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;HttpRequest&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HttpRequest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;newBuilder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
          &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;URI&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
          &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;sendAsync&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;BodyHandlers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ofString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt;
          &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;thenApply&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;HttpResponse:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;2 - Protocol Level&lt;/strong&gt;: As mentioned previously, HTTP is a synchronous protocol because the client issues a request and waits
for a response. Message queues on the other hand, are typically based on asynchronous protocols. RabbitMQ for example, 
is based on AMQP which is a much lighter weight protocol than HTTP and can operate in a “fire and forget” manner.
Using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nucleon.amqp&lt;/code&gt; python library, we can write code to publish an event to an AMQP based message queue in the following way.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;nucleon.amqp&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Connection&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Connection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;amqp://localhost/&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;queue_declare&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;test&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# This operation will return immediately
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;basic_publish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;routing_key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;test&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;Hello world!&apos;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Unlike an HTTP call, no response is returned from publishing a message to a queue, and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;basic_publish&lt;/code&gt; method returns immidiately. For this reason, the above statement regarding asynchronicity is true.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3 - Service Integration Level&lt;/strong&gt;: Asynchronous communication at this level is concerned with designing micoservices so that they do
not need to communicate with other services during their request/response cycle.  Why? Because at the end of day, the goal for a 
service is to be available to the end-user even if other services that are part of the whole system are offline or unhealthy.&lt;/p&gt;

&lt;p&gt;If a service needs to trigger some action in another service, it should be done outside of the request/response cycle.
Additionally, if a service relies on data that is located in another service, data should be replicated across the services using
eventual consistency. This also has the advantage of being able to translate that data into the language of your own Bounded Context.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/indepentent-microservice-databases.png&quot; alt=&quot;eventual_consistency&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The point here is that asynchronous service integration is an architectural design decision that is &lt;strong&gt;independent&lt;/strong&gt; of the specific
communication mechanism used. In theory, message queues could be used to &lt;em&gt;synchronously&lt;/em&gt; integrate services where they 
are designed to deliver and wait for messages from a message queue in a stateful way. Ofcourse, that would be a really poor design.&lt;/p&gt;

&lt;h2 id=&quot;do-you-agree&quot;&gt;Do you Agree?&lt;/h2&gt;
&lt;p&gt;I hope this blog post has shed some light on some common misunderstandings when it comes to the RESTful HTTP Calls Vs Message Queue
debate. I strongly feel that important architectural decisions such as these cannot be made with a “surface level” understanding of the
technologies involved, which is why I’ve tried to improve my understanding in this area.&lt;/p&gt;
</description>
        <pubDate>Thu, 05 Dec 2019 15:04:23 +0000</pubDate>
        <link>https://mfadhel.com/rest-message-queue/</link>
        <guid isPermaLink="true">https://mfadhel.com/rest-message-queue/</guid>
        
        <category>microservices</category>
        
        <category>distributed systems</category>
        
        <category>rest</category>
        
        <category>messaging</category>
        
        
      </item>
    
      <item>
        <title>Why Object Oriented Code Accelerates Microservices Adoption</title>
        <description>&lt;p&gt;&lt;strong&gt;All monoliths are not created equal&lt;/strong&gt;. Even with the best solution architects, developers, and financial resources available, a legacy application’s microservices transformation journey will be a nightmare if the code is &lt;em&gt;not object-oriented&lt;/em&gt;.
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;Wanting to benefit from scalability and cost-efficiency of cloud technologies, organizations are increasingly migrating their monolithic applications to microservices and serverless based architectures. Due to the nature of typical monoliths however, this migration is often a long and difficult process.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2udfzo.jpg&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The reason?&lt;/strong&gt; The most time consuming aspect of the migration journey involves &lt;em&gt;decoupling&lt;/em&gt; the monolith into smaller, more refined services while ensuring that these new components have desirable properties of a distributed system (autonomy, scalability, and so on).&lt;/p&gt;

&lt;p&gt;And this decoupling process will be much more frustrating and tedious than necessary if the code does not have certain characteristics that make it easy to split up and compose into smaller and more focussed components. In this article I’ll demonstrate how four key Object Oriented Programming principles &lt;strong&gt;accelerate&lt;/strong&gt; this process.&lt;/p&gt;

&lt;p&gt;By the end, I’m hopefull that you’ll seriously consider writing high quality Object Oriented code when starting your next greenfield project so that you can avoid many of the difficulties typically associated with microservices adoption down the road.&lt;/p&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#do-one-thing-well&quot; id=&quot;markdown-toc-do-one-thing-well&quot;&gt;Do One Thing Well&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#message-passing&quot; id=&quot;markdown-toc-message-passing&quot;&gt;Message Passing&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#coupling&quot; id=&quot;markdown-toc-coupling&quot;&gt;Coupling&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#information-hiding&quot; id=&quot;markdown-toc-information-hiding&quot;&gt;Information Hiding&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#in-closing&quot; id=&quot;markdown-toc-in-closing&quot;&gt;In Closing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;do-one-thing-well&quot;&gt;Do One Thing Well&lt;/h2&gt;

&lt;p&gt;Classes that take on many responsibilities or contain a lot of data, also known as God Classes, are very difficult to read, maintain, and extend due to their enormous size. For this reason, classes in an Object Oriented design should &lt;strong&gt;focus&lt;/strong&gt; on doing one thing well, and behave as a logically single, atomic unit. If the complexity of an object exceeds a reasonable level, it should be refactored into two or more separate entities.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/single-responsibility-principle.png&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When we consider that each service in a microservices architecture should focus on a specific domain, this method of designing classes gives us a great deal of &lt;strong&gt;flexibility&lt;/strong&gt; in determining how we want to decouple a monolithic application into such services.&lt;/p&gt;

&lt;p&gt;As an example, consider a scenario where a code base consists of many God classes. Clearly, your ability to decouple the application into services that focus on specific domains is severely limited because the basic building blocks of these services (i.e the objects themselves), are extremely broad and unfocused. In such scenarios, you’ll have to refactor those large classes into smaller components that have fewer responsibilities before you can compose them into microservices with the desired level granularity.&lt;/p&gt;

&lt;h2 id=&quot;message-passing&quot;&gt;Message Passing&lt;/h2&gt;

&lt;p&gt;Perhaps the most misunderstood aspect of Object Oriented systems is inter-object communication. In fact, &lt;strong&gt;a method call was not the way modules in an Object Oriented system were intended to communicate&lt;/strong&gt;, rather it was through &lt;a href=&quot;http://mfadhel.com/lost-oop/#inter-object-communication&quot;&gt;messaging&lt;/a&gt;.
&lt;br /&gt;&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet tw-align-center&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Communication in OOP should be thought as message passing, not method calls. Message passing results in smart objects that accomplish tasks together via content negotiation. Method calls result in many unintelligent objects that are constantly told how to do their job. &lt;a href=&quot;https://twitter.com/hashtag/oop?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#oop&lt;/a&gt;&lt;/p&gt;&amp;mdash; Muntazir Fadhel (@FadhelMuntazir) &lt;a href=&quot;https://twitter.com/FadhelMuntazir/status/1103057880520052736?ref_src=twsrc%5Etfw&quot;&gt;March 5, 2019&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;p&gt;&lt;br /&gt;
The difference between them is in the way we perceive method calls versus messages. Calling a method essentially puts the person making the method call in control of running the process. The caller gets the callee to do something and prevents it from doing something that the caller does not want. Message passing on the other hand revolves around &lt;strong&gt;negotiation&lt;/strong&gt;, and this is the key in building object-oriented systems.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/sciencev2.svg&quot; alt=&quot;message-passing&quot; /&gt;
&lt;strong&gt;Method calling vs content negotiation via message passing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A major challenge in converting a monolith into microservices based architecture lies in re-designing its communication mechanism. Microservices are ideally integrated using asynchronous communication to enforce microservice autonomy and to develop an architecture that is resilient when microservices fail or underperform.&lt;/p&gt;

&lt;p&gt;The problem arises when code is written in a procedural and imperative way. Breaking up a monolith that consists of such code into microservices will &lt;strong&gt;force&lt;/strong&gt; architects to implicitly use a synchronous communication pattern right from the onset when that might not be the most optimal solution.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/sync_vs_async.PNG&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;On the other hand, code that practices message passing facilitates the decoupling of a monolith into microservices that communicate using asynchronous patterns to a great degree. A module that practices message passing properly does not require any response from the client in other for it to continue doing it’s job. It does not control it’s clients, and assumes that any client modules receiving it’s messages are smart enough to do whatever needs to be done next. The final result of composing such objects into microservices is an architecture that can be adapted to use asynchronous communication mechanisms with little effort.&lt;/p&gt;

&lt;h2 id=&quot;coupling&quot;&gt;Coupling&lt;/h2&gt;

&lt;p&gt;Coupling represents the degree to which a module or object is independent from others. A highly Coupled module relies on and modifies the states and internals of other objects to do its job, whereas a loosely Coupled module relies on a minimal set of interfaces belonging to other objects to do its job.&lt;/p&gt;

&lt;p&gt;Object Oriented systems generally avoid highly Coupled modules since they are increasingly difficult to maintain and test as more components are introduced into the system. Unsurprisingly, distributed cloud architectures also favour the design of services and components that do not rely on many other components to do its job. In this case however, the motivating goal is to support &lt;strong&gt;component evolution&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/coupling.PNG&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;That is to say, components in a distributed architecture should have the ability to be changed, upgraded, or replaced independently without affecting the functioning of other components. This requires microservices to be designed in a way that makes them primarily responsible for &lt;em&gt;running their own show&lt;/em&gt;. In return, teams responsible for different services will have the autonomy to make decisions and act independently from each other.&lt;/p&gt;

&lt;p&gt;With that said, you can only decouple your monolith into services that maintain their autonomy to the degree of autonomy the individual objects composing those services have, which comes down to Coupling. Therefore, &lt;em&gt;loosely&lt;/em&gt; coupled code will lend itself to autonomous services, while highly coupled code will need a a lot of refactoring before it can achieve this goal.&lt;/p&gt;

&lt;h2 id=&quot;information-hiding&quot;&gt;Information Hiding&lt;/h2&gt;

&lt;p&gt;Information Hiding refers to the process of writing modules in a way that keeps their details relating to core design decisions, especially those that are expected to change, &lt;strong&gt;hidden&lt;/strong&gt; from other objects. As a result, callers of an object are effectively decoupled from it’s internal workings, which makes it possible for the ‘hidden’ parts to change without needing to change the way the object is called.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/Information-hiding.png&quot; style=&quot;margin-left:auto; margin-right:auto; display: block;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This principle is also a desirable property for components in micoservices/serverless based architecture. A microservice for example, should be designed as a black box in which its internal complexity and details are hidden from other services in the system. Because of this, communication between services can now take place via well defined APIs, which is a desirable trait of microservice architectures.&lt;/p&gt;

&lt;p&gt;It should be easy to see now why the process of decoupling a monolith that practices Information Hiding into microservices that behave as black boxes is a straight forward task. Simply put, each class that practices Information Hiding already behaves as a mini black box of sorts, which makes composing them into larger microservices that behave as black boxes a trivial exercise.&lt;/p&gt;

&lt;p&gt;On the other hand, if Information Hiding is not properly observed in the original code, you are at risk of decoupling the monolith into microservices that &lt;em&gt;depend on the internal workings of other microservices to provide their service&lt;/em&gt;. Obviously, this will hurt the maintainability and evolution of the overall architecture.&lt;/p&gt;

&lt;h2 id=&quot;in-closing&quot;&gt;In Closing&lt;/h2&gt;

&lt;p&gt;The functioning and design of an ideal microservice shares many characteristics with the functioning and design of an ideal object in an object-oriented system. For this reason, any process of migrating a monolithic application to a microservices-like architecture will be greatly simplified if the application exhibits good object-oriented practices in the first place.&lt;/p&gt;
</description>
        <pubDate>Mon, 25 Feb 2019 15:04:23 +0000</pubDate>
        <link>https://mfadhel.com/object-oriented-microservices-migrations/</link>
        <guid isPermaLink="true">https://mfadhel.com/object-oriented-microservices-migrations/</guid>
        
        <category>microservices</category>
        
        <category>oop</category>
        
        <category>software architecture</category>
        
        <category>refactoring</category>
        
        
      </item>
    
      <item>
        <title>4 Elements of A Great Serverless Application Deployment Strategy</title>
        <description>&lt;p&gt;&lt;em&gt;Serverless&lt;/em&gt; is the new Buzz word in town, selling developers the ability to focus on writing applications instead of managing servers.&lt;/p&gt;

&lt;p&gt;This is true for the most part, but Serverless apps also have a certain property that can make their deployment and maintenance time consuming. That is, they depend on services - lots of them. A serverless architecture is typically designed over services for storing data, load balancing, data caching and code execution, just to name a few.&lt;/p&gt;

&lt;p&gt;With that said, how do you both provision infrastructure and deploy code to test/staging/production environments in an &lt;strong&gt;automated&lt;/strong&gt; and &lt;strong&gt;risk-minimized&lt;/strong&gt; way?&lt;/p&gt;

&lt;p&gt;If you can’t answer this question easily, or some part of your deploys still require you to look at your cloud provider’s console, then this post is for you.
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/Continuous-Delivery-and-Deployment.jpg&quot; alt=&quot;cd_img&quot; /&gt;&lt;/p&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#separate-environments-properly&quot; id=&quot;markdown-toc-separate-environments-properly&quot;&gt;Separate Environments Properly&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#continuous-delivery&quot; id=&quot;markdown-toc-continuous-delivery&quot;&gt;Continuous Delivery&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#app-config-is-stored-in-the-environment&quot; id=&quot;markdown-toc-app-config-is-stored-in-the-environment&quot;&gt;App Config Is Stored in the Environment&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#infrastructure-is-provisioned-and-deployed-as-code&quot; id=&quot;markdown-toc-infrastructure-is-provisioned-and-deployed-as-code&quot;&gt;Infrastructure is Provisioned and Deployed as Code&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#closing&quot; id=&quot;markdown-toc-closing&quot;&gt;Closing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;separate-environments-properly&quot;&gt;Separate Environments Properly&lt;/h2&gt;
&lt;p&gt;To lessen the risk of integrating new code, most teams  setup various environments to test the robustness of submitted code before it is pushed to production.&lt;/p&gt;

&lt;p&gt;When configuring serverless architectures in these environments, special care needs to be taken in deciding whether a &lt;strong&gt;single stack&lt;/strong&gt; or &lt;strong&gt;multi-stack approach&lt;/strong&gt; architecture is best for your project. Otherwise, you might be wasting a lot of time on deployments, or even worse, introducing unnecessary risk to your application.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/staging_prod_single.svg&quot; alt=&quot;staging_prod_single_architecture&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;single stack&lt;/em&gt; approach shares its services and infrastructure &lt;strong&gt;across all&lt;/strong&gt; environments (like test, staging and prod). To differentiate between environments at runtime, environment variables or similar mechanisms are used.&lt;/p&gt;

&lt;p&gt;In the context of a serverless app deployed on AWS, a single stack setup might configure a single Lambda Function with multiple aliases, an API Gateway with multiple stages, and a DynamoDB service with multiple tables - all with the purpose of supporting multiple test, staging and production environments.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/staging_prod_multi.svg&quot; alt=&quot;staging_prod_architecture&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In contrast, a &lt;em&gt;multi-stack&lt;/em&gt; approach uses a &lt;strong&gt;separate&lt;/strong&gt; instance of each service for every environment and does not use API stages or Lambda aliases to differentiate between them.&lt;/p&gt;

&lt;p&gt;Using the AWS example again, a multi-stack setup would configure a separate Lambda Function, API Gateway, and DynamoDB instance for each environment.
&lt;br /&gt;&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet tw-align-center&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;The core difference between a multi-stack and single stack approach in multi-environment architectures is that a multi-stack approach minimizes risk, while a single stack approach is easier to configure and maintain. &lt;a href=&quot;https://twitter.com/hashtag/Serverless?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#Serverless&lt;/a&gt; &lt;a href=&quot;https://twitter.com/hashtag/AWS?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#AWS&lt;/a&gt; &lt;a href=&quot;https://twitter.com/hashtag/deployment?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#deployment&lt;/a&gt;&lt;/p&gt;&amp;mdash; Muntazir Fadhel (@FadhelMuntazir) &lt;a href=&quot;https://twitter.com/FadhelMuntazir/status/1102941857733054471?ref_src=twsrc%5Etfw&quot;&gt;March 5, 2019&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;p&gt;&lt;br /&gt;
If something goes wrong in a single stack approach, there is a greater chance that your production systems are negatively impacted as well. After all, the environments in this approach are provisioned on top of each other, and rely only on environment variables and lambda aliases for indirection.&lt;/p&gt;

&lt;p&gt;In the multi-stack approach, this probability is decreased as a result of using separate resources for each environment. This advantage comes at a cost however - multi-stack approaches require more work to configure and maintain in comparison to single stack architectures. And in most scenarios, they are more expensive to run as well.&lt;/p&gt;

&lt;p&gt;If you are in the early stages of your project, it might be a better idea for you to run with a single stack approach. Otherwise, a multi-stack approach is the way to go.&lt;/p&gt;

&lt;h2 id=&quot;continuous-delivery&quot;&gt;Continuous Delivery&lt;/h2&gt;
&lt;p&gt;The main idea behind Continuous delivery is to produce &lt;strong&gt;production ready&lt;/strong&gt; artifacts from your code base frequently in an &lt;strong&gt;automated fashion&lt;/strong&gt;. It  ensures that code can be rapidly and safely deployed to production by delivering every change to a production-like environment and that any business applications and services function as expected through rigorous automated testing.&lt;/p&gt;

&lt;p&gt;&lt;img style=&quot;display:block;&quot; src=&quot;/images/Worked-Fine-In-Dev-Ops-Problem-Now.jpg&quot; alt=&quot;sample_comment&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The most important point however, is that all of this must be &lt;strong&gt;automated&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Using their front end web application, Cloud providers such as Amazon Web Services &lt;em&gt;make it easy&lt;/em&gt; to spin off a new lambda function for testing purposes or to update a function’s application code. However, all aspects of your continuous delivery strategy should be &lt;strong&gt;automated&lt;/strong&gt; - the only manual step should be the push of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deploy to production&lt;/code&gt; button. This is vital for many reasons:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Minimizing Risk&lt;/strong&gt; - Even with proper resource access controls in place which is seldom the case, the risk of accidentally causing bad things to happen are higher than you think. You definitely don’t want be the reason for a disruption to your service.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scalability&lt;/strong&gt; - As the number of developers in the project grows, and by extension, the volume of code deliveries, any process that is not completely automated will likely slow down your team’s agility.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Traceability&lt;/strong&gt; - When your continuous delivery strategy is an automated, often using an automated pipeline of some sort, the use of  deployments, builds and other components are better documented, making it easier to resolve and recover from failures.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;/images/deployments_video_edited.gif&quot; alt=&quot;bitbucket_deploy&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Using Bitbucket pipelines, I usually use the following skeleton pipeline in multi-environment, continuous delivery environments. First, it runs your static analysis tools and automated tests for every Pull Request. Once the changes are deployed to master, it automatically updates the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;STAGING&lt;/code&gt; environment. Finally, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PROD&lt;/code&gt; environment is updated once the changes in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;STAGING&lt;/code&gt; are known to be safe using a manual trigger. If you are using AWS, checkout &lt;a href=&quot;https://bitbucket.org/awslabs/&quot;&gt;this repo&lt;/a&gt; for more information on the actual automated deployment of Lambda functions.&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;pipelines&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Run Static Analysis Tools&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;s&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Run Automated Tests&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;s&quot;&gt;...&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;branches&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;master&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Run Static Analysis Tools&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;...&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Run Automated Tests&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;...&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Update STAGING&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;deployment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;staging&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;(deploy to staging)...&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Update PROD&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;deployment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;production&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;trigger&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;manual&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;(deploy to production)...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;app-config-is-stored-in-the-environment&quot;&gt;App Config Is Stored in the Environment&lt;/h2&gt;
&lt;p&gt;An app’s config consists of everything that is likely to vary between deploys (staging, production, developer environments, etc). This typically includes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Resource handles to the database, cache or any other attached resources&lt;/li&gt;
  &lt;li&gt;Credentials to external services such as Amazon S3 or Twitter&lt;/li&gt;
  &lt;li&gt;Per-deploy values such as the canonical hostname for the deploy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apps sometimes store config variables as constants in source code which is problematic for several reasons. First, any security sensitive related config data is visible to everyone who has access to the source code, which poses a serious security concern.&lt;/p&gt;

&lt;p&gt;Additionally, config varies substantially across deploys, whereas code does not. Developing code that dynamically detects the environment and sets the appropriate config data as required results in code that is unnecessarily complicated and difficult to maintain, especially as the number of environments/deploys increases. On top of this, any required changes to an environment config requires pushing a change through the code base and waiting for it to propagate through the software delivery pipeline which is tedious and slow.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/security-keys-meme.jpg&quot; alt=&quot;security_keys&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Rather than keeping your config data in source code, consider using consider using a service dedicated for this purpose like &lt;a href=&quot;https://aws.amazon.com/secrets-manager/&quot;&gt;AWS Secrets Manager&lt;/a&gt;. Or as a slightly less safe but commonly used alternative, store this data in environment variables. Now your application can simply refer to abstract variables for config info, which are dynamically set by a build pipeline during deployment. In this way, environment variables can be leveraged to  generate flexible and infinite variations (test, staging, prod, etc..) of your environment template. Lastly, environment variables are OS and language agnostic, which means they can easily be integrated across all types of projects.&lt;/p&gt;

&lt;h2 id=&quot;infrastructure-is-provisioned-and-deployed-as-code&quot;&gt;Infrastructure is Provisioned and Deployed as Code&lt;/h2&gt;

&lt;p&gt;Infrastructure as Code (IaC) is all about provisioning and updating entire workloads (applications, infrastructure) using code. The idea here is that the same engineering discipline that is typically used for application code can be applied to deploying and managing workloads as well. You can implement your operations procedures as code and automate their execution by triggering them in response to events.&lt;/p&gt;

&lt;p&gt;By using code to automate the process of setting up and configuring a virtual machine or container for example, you have a &lt;strong&gt;fast&lt;/strong&gt; and &lt;strong&gt;repeatable&lt;/strong&gt; method for replicating the process. So if you build a virtual environment for the development of an application, you can repeat the process of creating that VM simply by running the same code once you are ready to deploy.&lt;/p&gt;

&lt;p&gt;Additionally, IaC processes increase agility. Developers don’t have to wait for however long the IT department needs to provision a new VM for them to do work.&lt;/p&gt;

&lt;p&gt;When it comes to practicing IaC in the cloud, the &lt;a href=&quot;https://serverless.com&quot;&gt;Serverless Framework&lt;/a&gt; is a great tool for configuring serverless architectures. It’s a command line interface for building and deploying entire serverless applications through the use of configuration template files. It, along with many other services including AWS’s Serverless Application Model (SAM) for example, provide a scalable and systematic solution to many of the operational complexities of multi-environment serverless architectures. The &lt;a href=&quot;https://serverless.com&quot;&gt;Serverless Framework&lt;/a&gt; is probably the most popular cloud provider agnostic framework for configuring serverless applications and supports AWS, Microsoft Azure, Google Cloud Platform, IBM OpenWhisk, and more.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/infra-as-code-schema.png&quot; alt=&quot;infra_as_code&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The typical serverless application uses a combination of cloud services, which often need to be configured  and setup separately for each environment.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://serverless.com&quot;&gt;Serverless&lt;/a&gt; makes this process much more straight forward and scalable by utilizing a component based configuration where all the infrastructure and code for your entire application can be provisioned easily. Not only do these components conveniently refer to commonly used serverless services (AWS: S3 buckets, lambda functions, API Gateways, etc..), they can be re-used and  composed into higher level components to build entire serverless applications. Components are open source, and there is lots of pre-built functionality developers can tap into right away.&lt;/p&gt;

&lt;p&gt;As mentioned in the previous section, an automated continuous delivery solution is key for your serverless application. Serverless frameworks can be easily integrated into CI/CD pipeline to deploy sophisticated serverless applications in one step, making it much easier to manage multi-environment configurations.&lt;/p&gt;

&lt;h2 id=&quot;closing&quot;&gt;Closing&lt;/h2&gt;

&lt;p&gt;Serverless applications often consist of plucking and combining various services and packages together which can make keeping track of everything a complex process, especially when running multi-environment setups.&lt;/p&gt;

&lt;p&gt;In such scenarios, I feel it’s important that processes surrounding Serverless architectures should be scalable, automated, and require little manual intervention. This list represents my thoughts on how to deal with the complexity.&lt;/p&gt;
</description>
        <pubDate>Sat, 05 Jan 2019 15:04:23 +0000</pubDate>
        <link>https://mfadhel.com/best-practices-deploying-serverless-architectures/</link>
        <guid isPermaLink="true">https://mfadhel.com/best-practices-deploying-serverless-architectures/</guid>
        
        <category>aws</category>
        
        <category>serverless</category>
        
        <category>ci/cd</category>
        
        <category>infrastructure as code</category>
        
        <category>devops</category>
        
        
      </item>
    
      <item>
        <title>Dissecting GitHub Code Reviews: A Text Classification Experiment</title>
        <description>&lt;p&gt;&lt;a href=&quot;http://makeapullrequest.com&quot;&gt;&lt;img src=&quot;https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square&quot; alt=&quot;PRs Welcome&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;https://github.com/ellerbrock/open-source-badges/&quot;&gt;&lt;img src=&quot;https://badges.frapsoft.com/os/v2/open-source.svg?v=103&quot; alt=&quot;Open Source Love&quot; /&gt;&lt;/a&gt; &lt;a class=&quot;github-button&quot; href=&quot;https://github.com/Zir0-93/What-Code-Reviewers-Talk-About-Blog-Post&quot; data-show-count=&quot;true&quot; aria-label=&quot;Star Zir0-93/What-Code-Reviewers-Talk-About-Blog-Post on GitHub&quot;&gt;Star&lt;/a&gt;
&lt;br /&gt;
As part of the code review process on GitHub, developers can leave comments on portions of the unified diff of a GitHub pull request. These comments are extremely valuable in facilitating technical discussion amongst developers, and in allowing developers to get feedback on their code submissions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But what do code reviewers usually discuss in these comments?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In an effort to better understand code reviewing discussions, we’re going to create an SVM classifier to classify over 30 000 GitHub review comments based on the main code-related topic addressed by each comment (e.g. naming, readability, etc.).
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Grab the Jupyter Notebook for this experiment on &lt;a href=&quot;https://github.com/Zir0-93/What-Code-Reviewers-Talk-About-Blog-Post&quot;&gt;GitHub&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img style=&quot;display:block;&quot; src=&quot;/images/i-was-told-there-would-be-a-review.jpg&quot; alt=&quot;sample_comment&quot; /&gt;&lt;/p&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#review-comment-classifications&quot; id=&quot;markdown-toc-review-comment-classifications&quot;&gt;Review Comment Classifications&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#loading-the-data-set&quot; id=&quot;markdown-toc-loading-the-data-set&quot;&gt;Loading The Data Set&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#preprocessing-the-data&quot; id=&quot;markdown-toc-preprocessing-the-data&quot;&gt;Preprocessing The Data&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#extracting-features&quot; id=&quot;markdown-toc-extracting-features&quot;&gt;Extracting Features&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#training-the-classifier&quot; id=&quot;markdown-toc-training-the-classifier&quot;&gt;Training The Classifier&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#classifying-github-review-comments&quot; id=&quot;markdown-toc-classifying-github-review-comments&quot;&gt;Classifying GitHub Review Comments&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#discussion&quot; id=&quot;markdown-toc-discussion&quot;&gt;Discussion&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#closing&quot; id=&quot;markdown-toc-closing&quot;&gt;Closing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;review-comment-classifications&quot;&gt;Review Comment Classifications&lt;/h2&gt;

&lt;p&gt;The list of classifications we’re going to incorporate into our classifier are summarized in the table below. This list was developed based on a manual survey of approximately 2000 GitHub review comments I performed on randomly selected, but highly forked Java repositories on GitHub.&lt;/p&gt;

&lt;p&gt;The selected categories reflect the most frequently occurring topics encountered in the surveyed review comments. Majority of the categories are related to code level concepts (e.g. variable naming, exception handling); however, certain review comments 
that did not naturally fall into any existing categories and were unrelated to the overall goal of code reviewing were placed in
the “other” category.&lt;/p&gt;

&lt;p&gt;In situations where a review comment discussed more than one subject, I gave it a classification according 
to the topic it spent the most words discussing.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Category&lt;/th&gt;
      &lt;th&gt;Label&lt;/th&gt;
      &lt;th&gt;Further Explanation&lt;/th&gt;
      &lt;th&gt;     Sample Comment      &lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Readability&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;Comments related to readability, style, general project conventions.&lt;/td&gt;
      &lt;td&gt;“This code looks very convoluted to me”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Naming&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;“I think foo would be a more appropriate name”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Documentation&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;Comments related to licenses, package info, module documentation, commenting.&lt;/td&gt;
      &lt;td&gt;“Please add a comment here explaining this logic”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Error/Resource Handling&lt;/td&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;Comments related to exception/resource handling, program failure,  termination analysis, resource .&lt;/td&gt;
      &lt;td&gt;“Forgot to catch a possible exception here”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Control Structures/Program Flow&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;Comments related to usage of loops, if-statements, placement of individual lines of code.&lt;/td&gt;
      &lt;td&gt;“This if-statement should be moved after the while loop”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Visibility/ Access&lt;/td&gt;
      &lt;td&gt;6&lt;/td&gt;
      &lt;td&gt;Comments related to access level for classes, fields, methods and local variables.&lt;/td&gt;
      &lt;td&gt;“Make this final”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Efficiency / Optimization&lt;/td&gt;
      &lt;td&gt;7&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;“Many unnecessary  calls to foo() here”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Code Organization/ Refactoring&lt;/td&gt;
      &lt;td&gt;8&lt;/td&gt;
      &lt;td&gt;Comments related to extracting code from methods and classes, moving large chunks of code around.&lt;/td&gt;
      &lt;td&gt;“Please extract this logic into a separate method”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Concurrency&lt;/td&gt;
      &lt;td&gt;9&lt;/td&gt;
      &lt;td&gt;Comments related to threads, synchronization, parallelism.&lt;/td&gt;
      &lt;td&gt;“This class does not look thread safe”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;High Level Method Semantics &amp;amp; Design&lt;/td&gt;
      &lt;td&gt;10&lt;/td&gt;
      &lt;td&gt;Comments relating to method design and semantics.&lt;/td&gt;
      &lt;td&gt;“This method should return a String”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;High Level Class Semantics &amp;amp; Design&lt;/td&gt;
      &lt;td&gt;11&lt;/td&gt;
      &lt;td&gt;Comments relating to class design and semantics.&lt;/td&gt;
      &lt;td&gt;“This should extend Foo”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Testing&lt;/td&gt;
      &lt;td&gt;12&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;“is there a test for this?”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Other&lt;/td&gt;
      &lt;td&gt;13&lt;/td&gt;
      &lt;td&gt;Comments not relating to categories 1-12.&lt;/td&gt;
      &lt;td&gt;“Looks good”, “done”, “thanks”&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;loading-the-data-set&quot;&gt;Loading The Data Set&lt;/h2&gt;
&lt;p&gt;Now we’ll discuss our SVM text classifier implementation. This experiment represents a typical supervised learning classification exercise.&lt;/p&gt;

&lt;p&gt;We’ll start by first loading our training data consisting of two files representing 2000 manually labeled comment-classification pairs. The &lt;a href=&quot;https://raw.githubusercontent.com/Zir0-93/What-Code-Reviewers-Talk-About-Blog-Post/master/data/review_comments.txt&quot;&gt;first file&lt;/a&gt; contains a review comment on each
line, while the &lt;a href=&quot;https://raw.githubusercontent.com/Zir0-93/What-Code-Reviewers-Talk-About-Blog-Post/master/data/review_comments_labels.txt&quot;&gt;second file&lt;/a&gt;  contains manually determined classifications for each corresponding review comment on each line.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;review_comments.txt&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readlines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    
&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;review_comments_labels.txt&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;classifications&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readlines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;preprocessing-the-data&quot;&gt;Preprocessing The Data&lt;/h2&gt;

&lt;p&gt;Next, we are going to preprocess the raw data in multiple steps to prepare it for use by our SVM classifier. First, we remove all
formatting characters from each comment that are associated with the Markdown syntax. This step is important because the additional 
formatting related characters introduced by the Markdown standard will negatively impact our classifier’s ability to recognize identical 
words.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;re&lt;/span&gt; 

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;formatComment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sub&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;\*|\[|\]|#|\!|,|\.|&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|;|\?|\(|\)|`.*?`&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sub&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;\.|\(|\)|&amp;lt;|&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt;
        

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;formatComments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;formatComment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;comment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  

&lt;span class=&quot;n&quot;&gt;formatComments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;A note on using stopwords and stemmers.&lt;/strong&gt; My experimental results showed that using off the shelf stopword lists and stemmers to preprocess the data slightly decreased the accuracy of the final classifier. This is why I have not used any of these techniques in this experiment.&lt;/p&gt;

&lt;h2 id=&quot;extracting-features&quot;&gt;Extracting Features&lt;/h2&gt;

&lt;p&gt;The next step of our preprocessing stage is to convert the comment reviews into numerical feature vectors. This will represent the review comments in a way that will allow them to be processed by our machine learning algorithms. To do this, we will use the bag of words method, which 
represents a sentence using a feature vector developed based on the number of occurrences of each
term, known as &lt;em&gt;term frequency&lt;/em&gt;. We’ll use the Scikit-learn Python library to create feature vectors for our 
review comments using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CountVectorizer&lt;/code&gt; module.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Extracting features from text files
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.feature_extraction.text&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CountVectorizer&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;count_vect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CountVectorizer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;comments_train_counts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count_vect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fit_transform&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;comments_train_counts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(1036, 2787)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We wil also experiment with incorporating the inverse document frequency statistic, a common technique used in text classification experiments. To understand how the technique works, consider a commonly occurring term like “the”. A simple bag of words model based only on term frequency would tend to incorrectly emphasize review comments which happen to use the word “the” more frequently, without giving enough weight to the more meaningful terms like “variable” and “naming”. This is problematic as the term “the” is not a good keyword to distinguish relevant and non-relevant documents and terms, unlike the less-common words “variable” and “naming”. Hence the inverse document frequency factor is incorporated which diminishes the weight of terms that occur very frequently in the document set and increases the weight of terms that occur rarely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Putting it all together, the weight the td-idf statistic assigns to a given term is:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Highest when the term occurs many times within a small number of review comments&lt;/li&gt;
  &lt;li&gt;Lower when the term occurs fewer times in a review comment, or occurs in many review comments&lt;/li&gt;
  &lt;li&gt;Lowest when the term occurs in virtually all review comments.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;
&lt;p&gt;At this point, we can view each review comment as a vector with one component corresponding to each term in the dictionary, together
with a weight for each component that is given by the tf-idf statistic. For dictionary terms that do not occur in a document, this
weight is zero. This vector form will prove to be crucial to the scoring and ranking capabilities of our SVM classifier.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# TF-IDF
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.feature_extraction.text&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TfidfTransformer&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;tfidf_transformer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TfidfTransformer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;comments_train_tfidf&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tfidf_transformer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fit_transform&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;comments_train_counts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;comments_train_tfidf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(1036, 2787)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now that the classifier itself is almost ready, an important consideration now is the amount of training data to use for testing the classifier.&lt;/p&gt;

&lt;p&gt;After ensuring that at least 100 review comments for most of the classification are present in our labeled data set, I experimented with different numbers of review comments
to see what gave the best results. 2000 review comments seemed to give a good enough accuracy for our purposes. We will therefore dedicate 80% of our 2000 GitHub review comments data to the training set, which we will use to train our SVM classifier. The remaining 20% of the data will be dedicated to the test set, which we will use to test the performance of the developed classifier.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.model_selection&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;train_test_split&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;comment_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;comment_test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;classification_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;classification_test&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;train_test_split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;classifications&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;test_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;training-the-classifier&quot;&gt;Training The Classifier&lt;/h2&gt;

&lt;p&gt;Lastly, we can complete our classifier by combining the components developed so far with the scikit SVM classifier using the scikit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pipeline&lt;/code&gt; module. The purpose of the pipeline is to assemble several steps that can be cross-validated together while setting different parameters. We also use the scikit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SGDClassifier&lt;/code&gt; module to train our SVM model using Stochastic Gradient Descent (SGD). SGD is an iterative based optimization technique. In this case, the technique modifies the SVM parameters on each training iteration to find a local optimum that produces the best results. We set the number of iterations for our estimator at 1000. As demonstrated below, our developed classifier scored an accuracy of 82% on the test data set.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Training Support Vector Machines - SVM and calculating its performance
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.metrics&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;classification_report&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.pipeline&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Pipeline&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.linear_model&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SGDClassifier&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;text_clf_svm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Pipeline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;vect&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CountVectorizer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;tfidf&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TfidfTransformer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()),&lt;/span&gt; 
                         &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;clf-svm&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SGDClassifier&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loss&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;hinge&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;penalty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;elasticnet&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;random_state&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))])&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;text_clf_svm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text_clf_svm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;classifications&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;predicted_svm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text_clf_svm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;predict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;comment_test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classification_report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classification_test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;predicted_svm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;                precision    recall  f1-score   support
                     1
                   0.83      0.83      0.83        71
                    10
                   0.91      0.83      0.87        24
                    11
                   0.88      0.70      0.78        20
                    12
                   0.70      0.93      0.80        15
                    13
                   0.76      0.93      0.84       108
                     2
                   0.75      0.75      0.75        16
                     3
                   0.91      0.86      0.89        36
                     4
                   0.85      0.82      0.84        28
                     5
                   0.86      0.74      0.79        34
                     6
                   0.89      0.94      0.92        18
                     7
                   1.00      0.25      0.40         4
                     8
                   1.00      0.37      0.54        19
                     9
                   0.86      0.86      0.86         7
avg / total        0.84      0.82      0.82        400
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;An f1-score of 82% doesn’t seem reliable enough for the purpose of classifying GitHub review comments. I realized that the incorporation of the tf-idf statistic, while useful in other text classification activities, is not the best choice for the classification of review comments.&lt;/p&gt;

&lt;p&gt;The reason for this can be traced to the treatment of &lt;strong&gt;uncommon words&lt;/strong&gt; in this technique. In a regular document, an uncommon word, like “abject” for example, would be valuable in classifying that document. Review comments also contain uncommon terms; however, these terms mostly reference source code entities which we would not want to our classifier to place a major importance on.&lt;/p&gt;

&lt;p&gt;If our labeled data set for example consisted of a review comment that read, “The Foo class has some formatting issues.”, we would manually assign the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Readability&lt;/code&gt; classification to this comment. The problem is because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Foo&lt;/code&gt; is an uncommon term, our tf-idf based SVM classifier would highly correlate this term with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Readability&lt;/code&gt; category, which is not what we want as any future review comments containing the term  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Foo&lt;/code&gt; would be given the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Readability&lt;/code&gt; classification with a very high probability.&lt;/p&gt;

&lt;p&gt;A solution to this problem would be to replace any source code entities referenced in review comments by a static string, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;SYMBOL&amp;gt;&lt;/code&gt; for example; However, this would be difficult to detect accurately. Therefore, we will simply revert the use of the tf-idf statistic, which raises the f1-score of our classifier significantly to 94%&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Training Support Vector Machines - SVM and calculating its performance
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.pipeline&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Pipeline&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.linear_model&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SGDClassifier&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;text_clf_svm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Pipeline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;vect&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CountVectorizer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()),&lt;/span&gt; 
                         &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;clf-svm&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SGDClassifier&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loss&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;hinge&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;penalty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;elasticnet&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;random_state&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))])&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;text_clf_svm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text_clf_svm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;classifications&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;predicted_svm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text_clf_svm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;predict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;comment_test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classification_report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classification_test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;predicted_svm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
                precision    recall  f1-score   support

                     1
                   0.94      0.94      0.94        71
                    10
                   1.00      0.92      0.96        24
                    11
                   1.00      0.95      0.97        20
                    12
                   1.00      0.93      0.97        15
                    13
                   0.88      0.98      0.93       108
                     2
                   0.94      1.00      0.97        16
                     3
                   0.97      1.00      0.99        36
                     4
                   0.96      0.93      0.95        28
                     5
                   1.00      0.91      0.95        34
                     6
                   1.00      0.94      0.97        18
                     7
                   1.00      0.75      0.86         4
                     8
                   1.00      0.74      0.85        19
                     9
                   1.00      1.00      1.00         7
avg / total        0.95      0.94      0.94        400
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;classifying-github-review-comments&quot;&gt;Classifying GitHub Review Comments&lt;/h2&gt;

&lt;p&gt;We will now leverage the classifier we created in the previous section to classify over 30000 GitHub review comments from the top 100
most forked Java repositories on GitHub. GitHub exposes a REST API that allows developers to interact with the platform, which we will use to mine our Review Comments.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;urllib.request&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;json&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# URL to consume GitHub REST API to retrieve the top 50 most forked repositories on GitHub
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;https://api.github.com/search/repositories?q=language:java&amp;amp;sort=forks&amp;amp;order=desc&amp;amp;per_page=100&amp;amp;page=1&apos;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Execute the HTTP GET request
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resp_text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlopen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;UTF-8&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# load the JSON response in a python object
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;repos_json_obj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resp_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, we’re going to use the GitHub REST API again to collect a list of all the review comments from each repository. Note, the code below will require you to add your own GitHub OAuth token if you wish to execute it yourself.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;##########################################
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;github_access_token&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;&amp;lt;GITHUB OAUTH TOKEN&amp;gt;&apos;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;##########################################
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# loop through our list of 100 most forked java repositories..
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;repo&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;repos_json_obj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;items&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# i is the current page number
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# URL to consume GitHub REST API to retrieve 100 review comments
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;https://api.github.com/repos/&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;repo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;owner&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;login&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; \
        &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;/&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;repo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;name&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;/pulls/comments?direction=desc&amp;amp;per_page=100&amp;amp;page=&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; \
        &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;&amp;amp;access_token=&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;github_access_token&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Execute the HTTP GET request and store response in object
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;json_obj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;
                              &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;
                              &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlopen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
                              &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
                              &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;UTF-8&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Store all review comments from the response
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json_obj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;Collected&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;review comments.&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collected 32512 review comments.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next we’ll categorize each review comment using our SVM classifier, and generate a donut chart demonstrating our results.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;palettable.tableau&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Tableau_10&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;matplotlib&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rcParams&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;font.size&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Data to plot
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;Readability&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Naming&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Documentation&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Error/Resource Handling&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
&lt;span class=&quot;s&quot;&gt;&apos;Control Structures/Code Flow&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Visiblity&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Efficiency&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Code Organization/Refactoring&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&apos;Concurrency&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Method Design/Semantics&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Class Design/Semantics&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Testing&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;Other&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;


&lt;span class=&quot;n&quot;&gt;sizes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;13&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;explode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.03&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;13&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# loop through review comments and score
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;review_comment&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;review_comments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text_clf_svm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;predict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;formatComment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;review_comment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;body&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])])[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Create a circle for the center of the plot
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;my_circle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Circle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.75&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;white&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Plot
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Tableau_10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hex_colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;autopct&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;%1.0f%%&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;explode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;explode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shadow&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;startangle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;140&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
&lt;span class=&quot;n&quot;&gt;fig&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gcf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;set_size_inches&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gca&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_artist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;my_circle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;html&gt;
	&lt;head&gt;		
		&lt;!-- amCharts javascript sources --&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;https://www.amcharts.com/lib/3/amcharts.js&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;https://www.amcharts.com/lib/3/pie.js&quot;&gt;&lt;/script&gt;
		

		&lt;!-- amCharts javascript code --&gt;
		&lt;script type=&quot;text/javascript&quot;&gt;
			AmCharts.makeChart(&quot;chartdiv&quot;,
				{
					&quot;type&quot;: &quot;pie&quot;,
					&quot;adjustPrecision&quot;: false,
					&quot;angle&quot;: 25,
					&quot;balloonText&quot;: &quot;[[title]]&lt;br&gt;&lt;span style=&apos;font-size:14px&apos;&gt;&lt;b&gt;[[value]]&lt;/b&gt; ([[percents]]%)&lt;/span&gt;&quot;,
					&quot;depth3D&quot;: 15,
					&quot;innerRadius&quot;: &quot;65%&quot;,
					&quot;minRadius&quot;: 8,
					&quot;pullOutRadius&quot;: &quot;8%&quot;,
					&quot;startRadius&quot;: &quot;1000%&quot;,
					&quot;outlineThickness&quot;: 2,
					&quot;titleField&quot;: &quot;category&quot;,
					&quot;valueField&quot;: &quot;column-1&quot;,
					&quot;fontSize&quot;: 14,
					&quot;theme&quot;: &quot;default&quot;,
					&quot;allLabels&quot;: [],
					&quot;balloon&quot;: {},
					&quot;titles&quot;: [],
					&quot;dataProvider&quot;: [
						{
							&quot;category&quot;: &quot;Readability&quot;,
							&quot;column-1&quot;: &quot;15&quot;
						},
						{
							&quot;category&quot;: &quot;Naming&quot;,
							&quot;column-1&quot;: &quot;3&quot;
						},
						{
							&quot;category&quot;: &quot;Documentation&quot;,
							&quot;column-1&quot;: &quot;7&quot;
						},
						{
							&quot;category&quot;: &quot;Error/Resource Handling&quot;,
							&quot;column-1&quot;: &quot;5&quot;
						},
						{
							&quot;category&quot;: &quot;Control Structures/Code Flow&quot;,
							&quot;column-1&quot;: &quot;6&quot;
						},
						{
							&quot;category&quot;: &quot;Visibility&quot;,
							&quot;column-1&quot;: &quot;2&quot;
						},
						{
							&quot;category&quot;: &quot;Efficiency/Optimization&quot;,
							&quot;column-1&quot;: &quot;1&quot;
						},
						{
							&quot;category&quot;: &quot;Code Organization/Refactoring&quot;,
							&quot;column-1&quot;: &quot;3&quot;
						},
						{
							&quot;category&quot;: &quot;Concurrency&quot;,
							&quot;column-1&quot;: &quot;1&quot;
						},
						{
							&quot;category&quot;: &quot;High Level Method Design/Semantics&quot;,
							&quot;column-1&quot;: &quot;4&quot;
						},
						{
							&quot;category&quot;: &quot;High Level Class Design/Semantics&quot;,
							&quot;column-1&quot;: &quot;5&quot;
						},
						{
							&quot;category&quot;: &quot;Testing&quot;,
							&quot;column-1&quot;: &quot;4&quot;
						},
						{
							&quot;category&quot;: &quot;Other&quot;,
							&quot;column-1&quot;: &quot;44&quot;
						}
					]
				}
			);
		&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;h3 style=&quot;margin-top: 50px; margin-bottom: -80px; text-align: center;&quot;&gt;GitHub Review Comment Classifications&lt;/h3&gt;
		&lt;div id=&quot;chartdiv&quot; style=&quot;width: 130%;  min-width: 600px; margin-left: -150px; height: 750px; background-color: #FFFFFF;&quot;&gt;&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;

&lt;h2 id=&quot;discussion&quot;&gt;Discussion&lt;/h2&gt;

&lt;p&gt;Many of the classifications are related to each other at a conceptual level. For example, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Readability&lt;/code&gt; problem may be caused due to poor use of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Control Structures&lt;/code&gt;. Therefore, it is important to note that the classifications were based only on what the &lt;strong&gt;review comments explicitly discussed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That is to say, if a comment read, “poor readability here”, we would expect it to be classified as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Readability&lt;/code&gt;. However, if the comment read, “This for loop should be moved before line 2”, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Control Structures&lt;/code&gt; would be its expected classification, despite readability being the motivating factor for the review suggestion. As mentioned previously, in cases where multiple classifications applied, the comment was classified to a category it spent the most words discussing.&lt;/p&gt;

&lt;p&gt;Interestingly, 15% of review comments were found to discuss &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Readability&lt;/code&gt;. This category of comments not only deals with formatting, project conventions and style, but also with  how easy the code is to follow for a human.&lt;/p&gt;

&lt;p&gt;While existing static analysis tools are effective in dealing with the former area, they lack the ability to check code effectively in the latter domain. This is supported by the fact that over 50% of the repositories included in our study had some form of static analysis tools checking their code. Additionally, a manual survey of 100 randomly sampled comments classified with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Readability&lt;/code&gt; pointed towards this idea as well. One such comment from my study is illustrated below. While the approach taken by the code contributor is correct, the code review has suggested an alternate approach that increases the clarity of the code.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/readability.png&quot; alt=&quot;read&quot; style=&quot;margin-right:auto; margin-left:auto;&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Error handling, class and method design were areas according to which a significant percentage of review comments were classified under. This does not come as a surprise, as these topics vary greatly in the way they are handled from program to program. Moreover, there is often no single correct way to go about their implementation, resulting in an increased amount of developer discussion, and thus review comments, that exist around them.&lt;/p&gt;

&lt;p&gt;The most surprising finding from this study is the fact that 44% of review comments were classified according to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Other&lt;/code&gt; category. This highlights a major limitation of our approach in using review comments &lt;strong&gt;alone&lt;/strong&gt; to understand the subject of typical code review discussions.&lt;/p&gt;

&lt;p&gt;Without the ability to extract meaningful information from the source code alongside the review comment, it is very difficult to understand what the comment alone is discussing.&lt;/p&gt;

&lt;p&gt;For example, the figure below illustrates a review comment targeted at a Java annotation for a field variable. However, without viewing the source code, it equally possible to suggest that the review comment is targeted at a method name, class name, or even source code documentation.&lt;/p&gt;

&lt;p&gt;Many review comments also contain references to source code entities. Without being able to reference them to the source code, their classification becomes a difficult task . Lastly, many review comments consisted of comments serving as a response to a previous comment, which do not always reveal information about the original subject of the discussion.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/pluralize.png&quot; alt=&quot;pluralize&quot; style=&quot;margin-right:auto; margin-left:auto;&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;closing&quot;&gt;Closing&lt;/h2&gt;

&lt;p&gt;This wraps up our experiment on classifying GitHub code review comments! Unfortunately, this experiment only sampled the top 100 most forked Java repositories on GitHub, I wonder how the results would change for different programming languages. If you do end up researching this, please share your results with me!&lt;/p&gt;

&lt;p&gt;Did these results match what you had in mind based on your experience doing code reviews? Let me know in the comments below.&lt;/p&gt;
</description>
        <pubDate>Mon, 10 Dec 2018 15:04:23 +0000</pubDate>
        <link>https://mfadhel.com/github-code-reviews/</link>
        <guid isPermaLink="true">https://mfadhel.com/github-code-reviews/</guid>
        
        <category>machine learning</category>
        
        <category>github</category>
        
        <category>code review</category>
        
        <category>nlp</category>
        
        <category>python</category>
        
        
      </item>
    
  </channel>
</rss>
