<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Boredhacking's RSS Feed]]></title><description><![CDATA[Blog discussing software engineering, web development, technology, and life ]]></description><link>https://boredhacking.com</link><generator>GatsbyJS</generator><lastBuildDate>Mon, 17 Aug 2026 04:36:52 GMT</lastBuildDate><item><title><![CDATA[Engineering Judgment Matters More Than Ever]]></title><description><![CDATA[I Don’t Code by Hand Anymore I don’t code by hand anymore, and I don’t personally know anyone else who does at this point. A few years ago…]]></description><link>https://boredhacking.com/coding-with-ai-agents-2026/</link><guid isPermaLink="false">https://boredhacking.com/coding-with-ai-agents-2026/</guid><pubDate>Sun, 16 Aug 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;I Don’t Code by Hand Anymore&lt;/h2&gt;
&lt;p&gt;I don’t code by hand anymore, and I don’t personally know anyone else who does at this point. A few years ago, that would have sounded unbelievable to me. I rarely even open code files locally. Most of the time, the first time I see the implementation is in a pull request. That doesn’t mean I skip reviewing the code. I read the diff as I normally would and still spend time validating the outcome. When I do open a local file, it is usually to share a specific snippet or some known information with another engineer or an agent.&lt;/p&gt;
&lt;p&gt;The most unbelievable part is that I’m able to ship more code than ever while leading a team and spending more time on product direction, strategy, and technical design. For well scoped work, agents can generally implement and test autonomously, and then I review the result like I would another developer’s. My friend &lt;a href=&quot;https://x.com/trevin&quot;&gt;Trevin Chow&lt;/a&gt; recently called this an “implementation sandwich”: the heavier parts for humans are planning on one side and testing and validation on the other, with implementation by the agent as the thinner middle layer. That feels pretty accurate to how I work today.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/coding-with-llms/&quot;&gt;Last September, I wrote about using LLMs to write the majority of my code&lt;/a&gt;. I was still guiding them closely and compared them to junior engineers. Then in January, I wrote that &lt;a href=&quot;/coding-with-llms-2026/&quot;&gt;the model and feedback loops mattered more than the prompts&lt;/a&gt;. A little over six months later, things have accelerated even more.&lt;/p&gt;
&lt;h2&gt;How I Got Here&lt;/h2&gt;
&lt;p&gt;My first foray into AI coding was GitHub Copilot autocomplete. It made me faster, but I was still typing code in my normal editor. Cursor was the next major workflow change. I was fairly early to agentic coding and started using Cursor’s chat-based agent around July 2024. I constantly tested models to find my main driver and gave the model most of my implementation work even back then.&lt;/p&gt;
&lt;p&gt;In late 2025, Claude Code with Opus 4.5 rapidly changed how I worked. Cursor’s agent could already search the codebase and run CLI tools, so those capabilities were not new. However, the combination of the model and harness felt more autonomous in Claude Code. It was also the point when I started moving most of my work out of an editor and into the terminal. As MCPs and skills became popular, I spent more time improving my agent harness and setup.&lt;/p&gt;
&lt;p&gt;Then, around March 2026, I moved from manually approving every action to using the new auto-approval mode in Claude Code. I never liked dangerously skipping permissions, but auto-approve let me retain control while getting out of the way. Over the last couple of months, Codex desktop has made it possible to do most of my job in an app that is neither an editor nor a terminal, which is a first for me.&lt;/p&gt;
&lt;p&gt;&lt;video autoplay loop muted playsinline controls preload=&quot;metadata&quot; poster=&quot;/media/engineering-judgment-2026/editor-terminal-desktop-poster.png&quot; aria-label=&quot;The workflow moving from a code editor, to a terminal, to a desktop coding agent interface.&quot;&gt;&lt;source src=&quot;/media/engineering-judgment-2026/editor-terminal-desktop.mp4&quot; type=&quot;video/mp4&quot; /&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;A big part of what has made this possible is tuning instruction files, skills, MCPs, CLIs, and other tools so agents can find information themselves. The other piece is ensuring agents have ways to validate their work, such as end-to-end tests, browser checks, API requests, or dry runs, with read-only access and approval for destructive actions where appropriate.&lt;/p&gt;
&lt;h2&gt;My Current Operating Model&lt;/h2&gt;
&lt;p&gt;Today, I spend roughly 80% of my time in Codex desktop and most of the remaining time in Claude Code via the terminal. Across both, I usually have five to ten active sessions for coding, writing documents, doing data analysis, thinking through strategy, or just discussing open-ended problems.&lt;/p&gt;
&lt;p&gt;Connections to existing systems help my agent sessions operate independently. For example, PostHog and Datadog access lets agents pull data and update dashboards without needing to write scripts or screenshot data. Agents have also lowered the activation energy for starting work. I no longer procrastinate on a coding task or document. I can start a conversation and iterate to something concrete quickly.&lt;/p&gt;
&lt;p&gt;My general workflow is to start by giving the agent as much context as possible, such as Slack threads, documents, past issues, the problem at hand, how I’m thinking about it, and the goal. We then iterate on a plan together. I don’t read the planning doc directly most of the time, but I generally read the synthesis in the chat thread and correct anything that doesn’t match my expectations. I also make sure we align on breaking the problem into digestible PRs, using stacks where needed. The agent then implements the change and runs the relevant checks, such as formatting, linting, existing tests, and as much end-to-end testing as it can. I review the pull request and give feedback if something is missing.&lt;/p&gt;
&lt;p&gt;Right now, Codex with GPT-5.6 Sol High is my default because the model is capable and cost-efficient. Claude Code and Anthropic models are still a useful part of my workflow, but they are harder for me to justify as costs rise relative to the gains I observe, especially when I burn through monthly token usage and need to pay for overage credits. At this point, I really only use Fable 5 as a thought partner for ideation and exploratory spikes, but I find it too expensive for day-to-day engineering work. The cost-to-quality ratio is not there as a daily driver.&lt;/p&gt;
&lt;p&gt;The last aspect of my daily agent use is an internally built system. Over the last six months, HeyGen has built an internal AI employee platform where employees can choose among several agent harnesses for a personal assistant. These agents are long-lived Slack bots that you can DM or ping in allowed Slack channels. I use mine for smaller coding tasks, finding root causes for bugs, fixing documentation, reviewing pull requests, testing, and running recurring tasks. The AI employee platform also includes a general-purpose coding agent that anyone can @mention in Slack to start a coding session. However, I still mostly rely on my personal agent because it has the skills, information, and setup I know and trust.&lt;/p&gt;
&lt;h2&gt;The Catch: Coding Ability Is Only Part of Engineering&lt;/h2&gt;
&lt;p&gt;My earlier comparisons of agents to junior and SWE II engineers still feel broadly right. The best models can approach senior-level execution on bounded work with clear direction and validation, but I’m not convinced they consistently operate as senior engineers. At least not in my eyes. Coding ability is only one part of being a senior engineer. For example, agents are bad at knowing when existing code needs a refactor instead of another change layered on top.&lt;/p&gt;
&lt;p&gt;Larger gaps include the ability to reuse existing work, weigh organizational history, recognize tradeoffs, apply taste, choose priorities, and involve people early. This is especially critical because a lot of information lives in old Slack threads, incidents, docs, and people’s memories rather than the codebase.&lt;/p&gt;
&lt;p&gt;For smaller requests, I may only need a simple prompt, a few requirements, and a way to validate the work.&lt;/p&gt;
&lt;p&gt;For more substantial work, I still use a workflow similar to the one I used before AI:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We write a succinct PRD and get alignment with the right people.&lt;/li&gt;
&lt;li&gt;We write a design doc and get alignment again.&lt;/li&gt;
&lt;li&gt;We plan how the work can be implemented, tested, reviewed, and merged iteratively.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This may sound like a lot of process, but with agents, you can do it without slowing down. The docs don’t need to take days to write and review. They just need to capture the decisions and constraints so people can align and agents don’t make conflicting assumptions.&lt;/p&gt;
&lt;p&gt;Without human alignment, an agent can generate a huge stack of PRs before anyone reviews the direction. Keeping pull requests and PR stacks small was necessary before agents, and it is still practical now. Each diff should be understandable, testable, deployable, and reversible. Agent-based PR reviews can find obvious bugs and missing tests, but they cannot replace architectural or organizational knowledge that neither agent has.&lt;/p&gt;
&lt;p&gt;I recently saw this with a new API endpoint implementation. We skipped design review and human alignment, so we reimplemented existing capabilities, missed requirements, and created reliability issues. A later refactor reused what already existed and made it more reliable and complete. A quick design check and search for existing work likely would have saved time before starting the implementation.&lt;/p&gt;
&lt;h2&gt;What Remains Unfinished&lt;/h2&gt;
&lt;p&gt;Today, each person manually assembles their own harness by adding skills and MCPs and constructing explicit loops. That scaffolding can only get you so far when agents are often too eager to start and finish the task. They don’t consistently push back, ask for missing information, or understand how I prefer to work. The most common failure I see is an agent acting on incorrect requirements instead of stopping to ask a question.&lt;/p&gt;
&lt;p&gt;My hypothesis is that stronger models and harnesses should remember useful workflows, identify tools, and improve reusable skills as they work. I see hints when an agent remembers a speedup or proactively reaches for the GitHub CLI. I think the next iteration of coding agents will also proactively set up their own loops and graphs of subagents for recurring tasks. More importantly, agents need reliable organizational information: decisions, designs, docs, and relevant messages that are up to date. A perfect system of record sounds difficult to manage, but maybe agents can make it easier to build and maintain.&lt;/p&gt;
&lt;p&gt;I think the next step is agents that do more than just execute. We aren’t there yet. Until then, strong engineering fundamentals are still what help me give an agent the right work, pick the right model for the task, and know whether the result is actually good. That is the part of engineering I spend most of my time on now.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Coding With LLMs in 2026: The Model Matters More Than the Prompts]]></title><description><![CDATA[Coding With LLMs in 2026: The Model Matters More Than the Prompts Agentic coding took a step-function leap in late 2025. Last year, I wrote…]]></description><link>https://boredhacking.com/coding-with-llms-2026/</link><guid isPermaLink="false">https://boredhacking.com/coding-with-llms-2026/</guid><pubDate>Sun, 18 Jan 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;Coding With LLMs in 2026: The Model Matters More Than the Prompts&lt;/h1&gt;
&lt;p&gt;Agentic coding took a step-function leap in late 2025.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/coding-with-llms/&quot;&gt;Last year, I wrote about using LLMs + agentic workflows&lt;/a&gt; to write most of my code. While the core principles hold, the nuance has shifted. In early 2026, the biggest variable between “AI slop” and production-grade code isn’t your prompting technique—it’s the model you pick and the feedback loops you build around it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prompting isn’t the blocker anymore. Feedback loops are.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;What’s Evolved: From SWE I to SWE II&lt;/h2&gt;
&lt;p&gt;Last year, I argued that you had to treat LLMs like junior developers (SWE I): they needed explicit breakdowns, struggled with ambiguity, and required constant hand-holding.&lt;/p&gt;
&lt;p&gt;By the end of 2025, we’ve clearly leveled up. Working with a top-tier agent now feels like collaborating with a SWE II:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Proactive Context&lt;/strong&gt;: They are better at navigating codebases and collecting context without being told exactly which file to open.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Autonomous Planning&lt;/strong&gt;: You can define higher-level constraints and acceptance criteria, letting the agent break the work down itself.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ambiguity Handling&lt;/strong&gt;: As long as there is enough “signal” (logs, docs, or types), they can fill in the gaps.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The missing pieces are still what you’d expect from a mid-level engineer: they lack “product taste” (knowing what not to build) and have a tendency to over-engineer if you don’t set guardrails.&lt;/p&gt;
&lt;h2&gt;The Model Matters More Than Ever&lt;/h2&gt;
&lt;p&gt;If the goal is speed to shipped impact, model choice dominates “prompt cleverness.” If you’re spending 30 minutes cleaning up “cheap model” output, you’re paying more in engineering time than you saved in tokens.&lt;/p&gt;
&lt;h3&gt;My 2026 Defaults&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Opus 4.5&lt;/strong&gt;: My daily driver. It’s the first model that felt visibly different for coding and general engineering tasks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GPT 5.2&lt;/strong&gt;: Still in the rotation for experimentation, but hasn’t yet unseated Opus for my daily coding.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gemini 3 (Pro/Flash)&lt;/strong&gt;: The standout for creativity. If I’m doing UI/UX or design thinking, it’s the most reliable partner for generating non-generic ideas(with context or prompting).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The Tooling Split: Claude Code &amp;#x26; Cursor&lt;/h2&gt;
&lt;p&gt;For most of last year, Cursor was my default. It’s still my main “pane of glass” for navigating code because, despite my best efforts, the full terminal/Vim life never quite stuck for me. I need a GUI.&lt;/p&gt;
&lt;p&gt;However, &lt;strong&gt;Claude Code has become my daily driver for actual execution.&lt;/strong&gt; But mostly within Cursor to easily review changesets.&lt;/p&gt;
&lt;h3&gt;Why the shift?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Usage-Based Pricing&lt;/strong&gt;: I started with Claude Code on my side projects. My side-project schedule is spiky. I’ll binge for a week and then do nothing for months. Claude Code’s “pay for what you use” model fits my lifestyle better than a flat monthly subscription.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Terminal + Editor Synergy&lt;/strong&gt;: It doesn’t limit me to the IDE. I can run it fully in the terminal or IDE without it feeling clunky.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Standardization&lt;/strong&gt;: It’s becoming the default internally at my company, making it easier to share reusable “agentic” patterns with teammates.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Trendsetter&lt;/strong&gt;: The Claude Code teams seems to be sending the standards for most agentic development and therefore using it gives you first access to new trends or best practices.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Lately, I use them in parallel: Claude Code for the long-running project thread, and Cursor for quick bugs or one-off edits that pop up while I’m working on something else.&lt;/p&gt;
&lt;p&gt;While I’ve done two or three multiple session at once this is still an area of improvement for me. I need to get more comfortable with work trees and multiple sessions in parallel.&lt;/p&gt;
&lt;h2&gt;The Real Unlock: Debugging &amp;#x26; Eval Loops&lt;/h2&gt;
&lt;p&gt;This is the part I’m doubling down on the hardest.&lt;/p&gt;
&lt;p&gt;Eval loops have always mattered in software development. Coming from a developer experience background, it’s funny to watch the industry “discover” this now—but it makes sense. Agents need the same thing humans do: a fast, reliable way to validate changes.&lt;/p&gt;
&lt;p&gt;Now that code creation is cheap, the bottleneck moves downstream to validation, confidence, and speed of iteration.&lt;/p&gt;
&lt;p&gt;Over the last few months, debugging has become almost fully autonomous. I recently started owning our external API, and most bugs were solved in one interaction.&lt;/p&gt;
&lt;h3&gt;The Context Packet&lt;/h3&gt;
&lt;p&gt;If you want an agent to behave like a strong engineer, give it the same “Context Packet” you’d give a teammate. This follows the same logic I wrote about years ago in &lt;a href=&quot;/seeking-help/&quot;&gt;&lt;em&gt;Seeking Help&lt;/em&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;High-level description of bug&lt;/li&gt;
&lt;li&gt;Endpoint/Component&lt;/li&gt;
&lt;li&gt;Input provided&lt;/li&gt;
&lt;li&gt;Output received&lt;/li&gt;
&lt;li&gt;Expected behavior&lt;/li&gt;
&lt;li&gt;What you’ve done so far or other context you’ve gathered&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Eval Loops Can Be Anything (As Long As They’re Fast and Reliable)&lt;/h3&gt;
&lt;p&gt;Depending on the work, your eval loop might be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Unit tests&lt;/li&gt;
&lt;li&gt;Integration tests&lt;/li&gt;
&lt;li&gt;Golden file snapshots&lt;/li&gt;
&lt;li&gt;End-to-end tests&lt;/li&gt;
&lt;li&gt;Local repro scripts&lt;/li&gt;
&lt;li&gt;Feature flags&lt;/li&gt;
&lt;li&gt;Dev/QA environments&lt;/li&gt;
&lt;li&gt;“Run the thing in the real distributed system and see if it behaves”&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The punchline: Your agent’s effectiveness is capped by how quickly it can prove it didn’t break anything or it met your requirements.&lt;/strong&gt; Your job is no longer writing the code; it’s building the loop.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Case Study: The “Slow Startup” Fix&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I had a service with a bloated Python startup time. Instead of me hunting imports, I gave the agent a loop:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It added startup logs to diagnose the bottleneck. It was flask blueprint initialization.&lt;/li&gt;
&lt;li&gt;It set up a profiling loop (&lt;code class=&quot;language-text&quot;&gt;PYTHONPROFILEIMPORTTIME=1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;It wrote a parser to sort the worst offenders.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;The Autonomy&lt;/strong&gt;: It then spent an afternoon identifying slow imports, moving them to runtime imports, re-running the profile, and repeating until the startup time stabilized.&lt;/p&gt;
&lt;p&gt;I didn’t drive the steps; I just provided the “profiling loop” and let the engine run.&lt;/p&gt;
&lt;h2&gt;Code Is Cheaper Than Ever—Don’t Be Afraid to Be Wasteful&lt;/h2&gt;
&lt;p&gt;Because code is now effectively free to generate, I’ve embraced “Wasteful Engineering.” I treat throwaway scripts as a default part of my workflow.&lt;/p&gt;
&lt;p&gt;When a clean eval loop doesn’t exist and it’s possible to test via code, the easiest move is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Write a one-off script that reproduces the issue or validates behavior&lt;/li&gt;
&lt;li&gt;Let the agent run it and iterate&lt;/li&gt;
&lt;li&gt;Delete it when you’re done&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I do this multiple times a day.&lt;/p&gt;
&lt;p&gt;Common “throwaway” artifacts I generate:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bug reproduction scripts (trigger hard-to-reach code paths)&lt;/li&gt;
&lt;li&gt;One-off scripts for backfills/migrations&lt;/li&gt;
&lt;li&gt;Scripts for pulling observability data (Datadog metrics, logs)&lt;/li&gt;
&lt;li&gt;Tiny HTML files for visualizing outputs (especially when evals spit out JSON)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Guardrails: Avoiding Footguns with Terminal Agents&lt;/h2&gt;
&lt;p&gt;Terminal-integrated agents are powerful—and that means you need guardrails.&lt;/p&gt;
&lt;p&gt;A few patterns that have worked well for me:&lt;/p&gt;
&lt;h3&gt;Secrets&lt;/h3&gt;
&lt;p&gt;We use &lt;strong&gt;Infisical&lt;/strong&gt; for secret storage and injection. That makes it easy to write scripts and give them the credentials they need without hardcoding anything. With infisical they are injected at runtime.&lt;/p&gt;
&lt;h3&gt;Production Data&lt;/h3&gt;
&lt;p&gt;I do write scripts that interact with production data to recreate customer issues, but most of them are &lt;strong&gt;read-only&lt;/strong&gt; operations (GET requests, database queries with no mutations).&lt;/p&gt;
&lt;h3&gt;Writes &amp;#x26; Destructive Actions&lt;/h3&gt;
&lt;p&gt;When the agent generates scripts that could mutate data, I push it toward safety by default:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Explicit confirmations (“type YES to proceed”)&lt;/li&gt;
&lt;li&gt;Dry-run flags&lt;/li&gt;
&lt;li&gt;Limiting scopes (single customer, single request ID)&lt;/li&gt;
&lt;li&gt;Verbose logging before executing changes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I want the agent to be fast, but I also want it to be safe.&lt;/p&gt;
&lt;h2&gt;Breaking Work Down Is Less Manual—But Still Necessary&lt;/h2&gt;
&lt;p&gt;Agents can handle more ambiguity and do more planning on their own now. That’s real.&lt;/p&gt;
&lt;p&gt;But you still need the work to land in a digestible, reliable way:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DB migration PR first&lt;/li&gt;
&lt;li&gt;Code changes next&lt;/li&gt;
&lt;li&gt;Avoid multi-thousand-line PRs nobody can review or safely roll back&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Agents can figure this out but you have to set the expectation early:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;“Propose PR boundaries”&lt;/li&gt;
&lt;li&gt;“Pause and ask before you touch migrations”&lt;/li&gt;
&lt;li&gt;“Stop and commit at checkpoints”&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is less about model limitations and more about good engineering hygiene.&lt;/p&gt;
&lt;h2&gt;Frontend Eval Loops (Promising, But Still Messier)&lt;/h2&gt;
&lt;p&gt;Backend eval loops are relatively easy to make deterministic.&lt;/p&gt;
&lt;p&gt;Frontend is improving, but it’s still messier. I’ve seen a few approaches emerge:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Playwright-based workflows&lt;/strong&gt; (including Playwright MCP) to control a browser for real UI validation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Claude browser extension + in-IDE browsers&lt;/strong&gt; for live feedback&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IDE-integrated “preview + test” loops&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I also think &lt;strong&gt;Antigravity&lt;/strong&gt; seems promising here because Google is well positioned to integrate Chrome deeply with their own IDE/tooling story.&lt;/p&gt;
&lt;p&gt;But in general, frontend eval reliability still feels behind backend. It’s getting better, it’s just not “solved” in the same way yet.&lt;/p&gt;
&lt;h2&gt;The 2026 Gap: Personal vs. Org Productivity&lt;/h2&gt;
&lt;p&gt;One of the biggest gaps is that agentic coding still rewards people who build more complex, opinionated setups.&lt;/p&gt;
&lt;p&gt;Cursor and Claude Code are both extensible (agents, prompts, MCPs, repo rules, etc.). Teams with time and expertise can assemble workflows that feel &lt;em&gt;shockingly&lt;/em&gt; autonomous. But most companies don’t have the expertise or the resources to build that configuration layer.&lt;/p&gt;
&lt;h3&gt;Everyone Is Building Their Own “Autonomous Stack”… and It’s Duplicative&lt;/h3&gt;
&lt;p&gt;This is something I’m watching play out at work in real time: a few of my coworkers are independently trying to develop their own “fully autonomous” workflows using the same set of tools and models.&lt;/p&gt;
&lt;p&gt;They’re all converging on similar patterns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Custom repo rules/prompts&lt;/li&gt;
&lt;li&gt;Pre-built sub-agents for recurring tasks (migrations, debugging, refactors)&lt;/li&gt;
&lt;li&gt;MCP integrations for internal context (docs, tickets, dashboards)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The problem is: &lt;strong&gt;everyone is reinventing some version of the same workflow&lt;/strong&gt;, and it’s not universal across the org.&lt;/p&gt;
&lt;p&gt;So even if a few people become 10x with their setup, the company doesn’t get a true step-function improvement—because the leverage isn’t shared. It stays stuck as “personal productivity wins” instead of “organizational capability.”&lt;/p&gt;
&lt;h3&gt;The Step-Function Jump Requires Standardization&lt;/h3&gt;
&lt;p&gt;If companies want real step-function gains in development velocity, they need to treat agentic workflows like internal platform infrastructure:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Make a “blessed” default&lt;/strong&gt; (the recommended setup every engineer can start with)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Centralize guardrails + patterns&lt;/strong&gt; (so safety and consistency aren’t optional)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Package reusable workflows&lt;/strong&gt; (debug loops, migration flows, PR chunking, release patterns)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Invest in eval loops org-wide&lt;/strong&gt; (because that’s the real limiter)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create a feedback channel&lt;/strong&gt; so the best individual workflows become shared defaults&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;My bet: &lt;strong&gt;2026 is the year this becomes a real platform function.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Agentic coding platforms will ship more opinionated, batteries-included defaults, and companies will need to meet them halfway with internal standards. Otherwise you’ll keep seeing the same story: a few people doing wizardry, everyone else doing “AI autocomplete,” and leadership wondering why velocity isn’t increasing as expected.&lt;/p&gt;
&lt;p&gt;We’re moving from a world of “writing code” to a world of “managing cycles.” The faster your loops, the faster you ship.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How Decision Matrices Create Better Engineering Decisions]]></title><description><![CDATA[Most design or decision documents include a pros and cons list for different approaches, but this rarely gives you an accurate comparison…]]></description><link>https://boredhacking.com/decision-matrix-vs-pros-cons-engineering-decisions/</link><guid isPermaLink="false">https://boredhacking.com/decision-matrix-vs-pros-cons-engineering-decisions/</guid><pubDate>Tue, 25 Nov 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Most design or decision documents include a pros and cons list for different approaches, but this rarely gives you an accurate comparison between two or more options.&lt;/p&gt;
&lt;p&gt;If you have more than two approaches, how can you accurately compare them based on pros and cons alone? The lists often contradict each other, don’t overlap enough, or emphasize different things. It becomes too easy to focus on certain points and miss others. And because each reviewer weighs bullets differently, two people looking at the same list can come to completely different conclusions.&lt;/p&gt;
&lt;p&gt;This is especially true across companies. Startups may prioritize velocity and simplicity, while more established companies optimize for scaling and robustness. Engineers from different backgrounds naturally emphasize different criteria.&lt;/p&gt;
&lt;p&gt;This is where decision matrices come into play.&lt;/p&gt;
&lt;p&gt;Instead of just a list of pros and cons, decision matrices require a &lt;strong&gt;predefined set of criteria&lt;/strong&gt; that each approach is weighed against. This gives you a more concrete comparison and ensures that each reviewer keeps the same criteria in mind. Not just their own bias. If a specific criterion should matter more, you can weigh it accordingly.&lt;/p&gt;
&lt;h2&gt;My First Encounter With Decision Matrices&lt;/h2&gt;
&lt;p&gt;At a previous company, I was leading the design for a project that overlapped heavily with two or three other projects happening at the same time. Our design had downstream impacts, and the other projects depended on it. Because of this, we needed alignment on a design that worked for &lt;em&gt;all&lt;/em&gt; systems so we could build in parallel.&lt;/p&gt;
&lt;p&gt;After the first design iteration, it became clear that we had conflicting priorities. Each group cared about different aspects, and this led to debates about what the system should look like and who should own which pieces.&lt;/p&gt;
&lt;p&gt;An engineering manager stepped in to help mediate and set direction. This is when I was introduced to my first decision matrix.&lt;/p&gt;
&lt;p&gt;They took our competing approaches (and a few they suggested themselves), listed out the shared criteria, and created a matrix comparing each approach against each criterion. While it didn’t resolve everything immediately, it reframed the conversation. We could now align on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the criteria that mattered most&lt;/li&gt;
&lt;li&gt;the leading design contenders&lt;/li&gt;
&lt;li&gt;how each design ranked across those criteria&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The actual decision wasn’t the hard part, agreeing on the &lt;strong&gt;criteria&lt;/strong&gt; and the &lt;strong&gt;tradeoffs&lt;/strong&gt; was. The decision matrix made that alignment possible.&lt;/p&gt;
&lt;h2&gt;How Decision Matrices Work&lt;/h2&gt;
&lt;p&gt;At a high level, decision matrices follow a simple process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Align on a set of criteria.&lt;/strong&gt; (e.g., extensibility, effort, reliability)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Define the grading or weighting scale&lt;/strong&gt; (1–N, or low/medium/high). I prefer numbers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create the table&lt;/strong&gt;: alternatives on one axis, criteria on the other.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rank each alternative across each criterion&lt;/strong&gt;, including notes on why.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compare alternatives directly&lt;/strong&gt; based on how well they meet the shared criteria&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You &lt;em&gt;can&lt;/em&gt; weight criteria, but I recommend weighting at most one. Otherwise you lose clarity on priorities.&lt;/p&gt;
&lt;h2&gt;What a Decision Matrix Looks Like in Practice&lt;/h2&gt;
&lt;p&gt;Recently, I had to document my reasoning for a technical decision after I had already made it. While slightly contrived, it shows what a realistic matrix might look like.&lt;/p&gt;
&lt;p&gt;The criteria included:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; – how easily we can iterate and change over time&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Production Readiness&lt;/strong&gt; – durability and reliability in real-world use&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Time to Implement&lt;/strong&gt; – how quickly we can ship with existing infra&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;User Experience&lt;/strong&gt; – the best possible UX given our time constraints&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We ranked three approaches from 1–3 for each criterion (3 being best):&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Approach&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Extensibility&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Production Readiness&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Time to Implement&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;User Experience&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Total Score&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Approach A&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;3 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;1 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;2 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;3 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;9&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Approach B&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;3 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;1 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;1 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;6&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Approach C&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;3 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;3 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;3 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;2 - &lt;em&gt;fill out why&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;11&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This made the decision much clearer not because one approach dominated in every category, but because &lt;strong&gt;it balanced the criteria best given our constraints.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The approach chosen:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;fit our existing architecture well, giving us production-ready background workflows&lt;/li&gt;
&lt;li&gt;was easy to implement using existing examples&lt;/li&gt;
&lt;li&gt;was extensible for future changes&lt;/li&gt;
&lt;li&gt;provided a decent UI (not the best, but good enough, with a path to improve)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Why Decision Matrices Work&lt;/h2&gt;
&lt;p&gt;Decision matrices work because they:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Force explicit criteria (no hidden priorities)&lt;/li&gt;
&lt;li&gt;Turn subjective debate into structured reasoning&lt;/li&gt;
&lt;li&gt;Document &lt;em&gt;why&lt;/em&gt; something was chosen, not just &lt;em&gt;what&lt;/em&gt; was chosen&lt;/li&gt;
&lt;li&gt;Make future revisits easier (“here’s what we optimized for back then”)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That said, they aren’t a silver bullet for every decision but they shine when multiple alternatives and competing priorities exist.&lt;/p&gt;
&lt;h2&gt;Where Else Can You Apply Decision Matrices&lt;/h2&gt;
&lt;p&gt;They aren’t just for engineering. You can use them for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Feature prioritization&lt;/strong&gt; (impact vs. effort is technically a decision matrix)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Vendor or tool selection&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Build vs. buy decisions&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Career paths or role comparisons&lt;/strong&gt; (with caution, not every personal decision fits this model)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Any time you have multiple options and can agree on shared criteria, a decision matrix helps you reason systematically with the information you have at that moment.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Decision matrices aren’t about “scoring” your choices. They make your reasoning transparent. Alignment comes from shared criteria and shared context.&lt;/p&gt;
&lt;p&gt;It’s easy to get overruled by a more senior or louder voice in the room. But if you aren’t aligned on the decision, using this process can help create that shared alignment.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Strong Opinions, Loosely Held: A Developer's Guide to AI Hype]]></title><description><![CDATA[At this point, a new 10x productivity AI tool is announced almost every week, if not every day. Without a doubt, I’m more productive today…]]></description><link>https://boredhacking.com/strong-opinions-loosely-held-guide-to-ai-hype/</link><guid isPermaLink="false">https://boredhacking.com/strong-opinions-loosely-held-guide-to-ai-hype/</guid><pubDate>Mon, 06 Oct 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;At this point, a new 10x productivity AI tool is announced almost every week, if not every day. Without a doubt, I’m more productive today using AI coding tools than I was a year ago, but I wouldn’t say it’s 10xed my productivity yet. I’ve tried out a number of tools over the last couple of years, and I always go into the evaluation with a healthy amount of skepticism. It’s normal to be skeptical of claims, and it’s healthy to avoid rushing in and doing proper due diligence. However, it’s impossible to ignore the power of AI coding and developer tools.&lt;/p&gt;
&lt;p&gt;That’s why it’s critical to balance skepticism with disciplined curiosity. A mindset best summarized by the phrase, &lt;strong&gt;‘strong opinions, loosely held’&lt;/strong&gt;. Static cynicism could lead to stagnation or, even worse, in your career. Curiosity and exploration, on the other hand, can be a superpower to accelerate your career. This is a mantra I follow not just for new pieces of software but software engineering in general.&lt;/p&gt;
&lt;p&gt;Over the last few years, I’ve often looked at an AI tool or piece of software and thought it was a fad, but I didn’t understand its value. It’s common to write things off when you don’t feel the problem or understand the solution; however, it’s important to be willing to try something out and evaluate it properly.That’s what this post is about: moving beyond the hype and focusing on a simple framework for identifying the real-world developer problems that a new generation of AI tools can solve.&lt;/p&gt;
&lt;h2&gt;The Endless Grind of Boilerplate and Repetitive Tasks&lt;/h2&gt;
&lt;p&gt;Most engineers get joy out of solving problems, writing elegant code, or seeing the successful output of their labor. However, most engineers don’t enjoy the monotonous aspects of coding, such as writing unit tests, boilerplate, and documentation. While there are many energizers in software engineering, there are also many drainers. Before AI coding tools, engineers had to constantly handle both the good and bad to successfully deliver good software; however, this isn’t necessarily the case anymore.&lt;/p&gt;
&lt;h3&gt;Taming the Grind with GitHub Copilot&lt;/h3&gt;
&lt;p&gt;Back when tools like &lt;a href=&quot;https://github.com/features/copilot&quot;&gt;GitHub Copilot&lt;/a&gt; first emerged and ChatGPT was starting to show the world what was possible, my initial sentiment was suspicion on its value potential. Having used ChatGPT with GPT-3 at the time I knew its code output was not great to say the least and pretty buggy. Not only that, I was pretty pessimistic about the future of AI coding in general because of how it would lack context. Without understanding larger codebases, how could it know what libraries or packages to use? However, another engineer on my team whom I respected told me he was enjoying GitHub Copilot and was very bullish on the future of AI coding over the next few years. Based on his recommendation, I started to test GitHub Copilot and quickly saw the benefits. We were coding in Kotlin at the time, and it could handle scaffolding out a lot of the boilerplate or picking the right functions needed to manipulate the main data abstractions. Writing boilerplate at the time was one of our company’s largest problems brought up by engineers, and Copilot could greatly improve productivity. It wasn’t a 10x or even 2x improvement, but it did raise my productivity by 20-30% at the time. As I got more used to Copilot and better at giving it context via code comments, pseudocode, open files, etc., it got even more useful.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;TIP: For inline auto completion surrounding context and comments are important. Pseudo code where possible and let the AI fill it in.&lt;/strong&gt; &lt;em&gt;(I’ve mostly replaced this flow with chat based coding as you’ll see next)&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;Evolving to Conversational Coding with Cursor&lt;/h3&gt;
&lt;p&gt;Now, when &lt;a href=&quot;https://cursor.com/&quot;&gt;Cursor&lt;/a&gt; and &lt;a href=&quot;https://www.claude.com/product/claude-code&quot;&gt;Claude Code&lt;/a&gt; started to gain hype, I was a lot less skeptical out of the gate but still a bit unsure of how different they could be. Cursor, though, was an even larger step improvement to me than GitHub Copilot. Cursor’s agent/chat window, which could directly edit files and tell you why, was a massive improvement to my productivity, especially in new codebases or languages. No longer did one need to spend time learning functions and libraries. Senior+ engineers who understand what good code and abstractions look like could easily describe in a prompt the exact steps and functionality they wished to use, what best practices to use, etc., and have it generated. With Cursor, I would say I quickly became not just a believer but an advocate for its usage. Anyone who wasn’t using Cursor or a chat-based workflow for coding was doing it wrong. Furthermore, as I learned to use the right models for thinking and coding, as well as giving the LLM the right context, it got even better. My opinions on AI coding have done a complete 180 over the last few years, going from pessimistic to bullish.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;TIP: Often you are pattern matching code from existing files in a codebase, online tutorials/examples, or stack overflow. Don’t skip this step with the LLM, still look for patterns where possible and feed this to the LLM as context.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;The High Cost and Friction of Model Experimentation&lt;/h2&gt;
&lt;p&gt;More recently, a friend of mine brought up &lt;a href=&quot;https://openrouter.ai/&quot;&gt;OpenRouter&lt;/a&gt; to me and asked for my opinion. Initially, I didn’t empathize with the problem it was trying to solve or completely understand its offering. The companies I had worked at had built their own clients for each LLM API to have proper telemetry and logging in place. My thought was, wouldn’t this be true for most production AI apps?&lt;/p&gt;
&lt;p&gt;However, when working on a side project recently with another engineer, they brought up OpenRouter and said they used it on their products, so I decided to give it a try. I quickly saw its usefulness. I think there were two big misunderstandings I had initially: 1) I didn’t realize OpenRouter centralized the billing and API access for you; I thought you would still need to set this up in each LLM provider. 2) I didn’t know how easy it was to integrate it into other clients, especially Vercel’s AI SDK. I was able to immediately set up an account, fund it, and integrate it into an app within an hour to test different models and providers.&lt;/p&gt;
&lt;p&gt;The friction to build AI tools was immediately lower using OpenRouter and the Vercel AI SDK, going from potentially days of setup and configuration to minutes. In my previous writings, I’ve discussed when to buy versus build, and setting LLM providers and access is not a differentiator at this point; it should be something you optimize for speed and maintenance costs (or the lack thereof). Picking the right tool to accelerate development and build prototypes is incredibly important. OpenRouter not only gives you this speed improvement, but it also allows you to quickly and easily A/B test different models or handle cost optimization across providers.&lt;/p&gt;
&lt;h2&gt;Evaluate Tools Based on the Problems They Solve&lt;/h2&gt;
&lt;p&gt;It’s important not just to buy into the hype without proper due diligence. Make sure you’re always asking yourself the question: “What specific, real-world problem does this solve for me?” And then, make sure to test it in a real-world setting, running it through a full, real application. This is another lesson from evaluating software providers and services. You need to come in with an opinion and give it a thorough test on real problems you or your team are facing. Remember: strong opinions, loosely held.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How I Use LLMs to Write the Majority of My Code]]></title><description><![CDATA[How I Use LLMs to Write the Majority of my Code What if I told you that I write less code by hand than I ever have, and I’m also moving…]]></description><link>https://boredhacking.com/coding-with-llms/</link><guid isPermaLink="false">https://boredhacking.com/coding-with-llms/</guid><pubDate>Thu, 18 Sep 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;How I Use LLMs to Write the Majority of my Code&lt;/h1&gt;
&lt;p&gt;What if I told you that I write less code by hand than I ever have, and I’m also moving faster than ever? That’s the reality, if done right, of working with LLMs as a staff engineer. Using LLMs to code is a hot topic nowadays, and I’ve seen a variety of posts almost every week on it. The most recent posts I’ve read that I highly agree with are &lt;a href=&quot;https://antirez.com/news/154&quot;&gt;this post by antirez&lt;/a&gt; and &lt;a href=&quot;https://www.sanity.io/blog/first-attempt-will-be-95-garbage&quot;&gt;this post by Vincent Quigley at Sanity&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Over the past couple of years, I’ve been using a range of LLM-powered tools to help me do my job more efficiently. I started out with GitHub Copilot, but over the last 10–12 months, I’ve shifted primarily to a combination of Cursor, ChatGPT, and Claude Code. I’d say I use Cursor still 60-70% of the time, Claude Code maybe 20-30% of the time, and ChatGPT the remaining 10-20% of the time.&lt;/p&gt;
&lt;p&gt;As a Staff Engineer, hands-on coding often isn’t the most valuable use of my time. I’m often more focused on defining abstractions, architecting systems, solving ambiguous problems, and breaking down projects. That being said when you work at an early stage startup you are probably still expected to code 80-90% of your time. That’s where AI assistants come in: they help handle the lower-level implementation work so I can stay focused on higher-leverage tasks. I treat AI like a junior engineer or research partner: someone to help write code, fix bugs, or explore new approaches.&lt;/p&gt;
&lt;p&gt;Sure, sometimes I worry that I’m outsourcing too much and letting my own coding muscles atrophy. But I’d rather be ahead of the curve and take full advantage of the incredible velocity gains LLMs can offer. I do go back and forth on trying to retake some coding responsibility from time to time. Over the last year I’ve used AI tools in a ton of different ways, and I thought it might be helpful to walk through some of those patterns. Both to reflect on what’s worked for me and to help others accelerate their own workflows.&lt;/p&gt;
&lt;p&gt;Here are a few quick principles that shape how I work with AI day‑to‑day:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Context is fuel&lt;/strong&gt;: Paste the relevant files, types, screenshots, and logs so the model can ground its answers in real code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lead, don’t delegate&lt;/strong&gt;: Break work into clear, bite‑size prompts the way you would mentor a junior engineer.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pick the right engine&lt;/strong&gt;: Swap models intentionally: heavyweight reasoning models for tricky bugs, lighter ones for boilerplate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pause &amp;#x26; ponder&lt;/strong&gt;: When the assistant stalls, step back, think through the system, and feed it the missing insight.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Version fearlessly&lt;/strong&gt;: Stage diffs early, reset chats often, and treat generations as disposable drafts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now let’s get into the details of how I’ve been using LLMs.&lt;/p&gt;
&lt;h2&gt;How I Actually Use LLMs in My Workflow&lt;/h2&gt;
&lt;h3&gt;Writing Frontend Code I Don’t Want to Master&lt;/h3&gt;
&lt;p&gt;Although I am a fullstack engineer, I lean more toward the backend. I understand the high-level concepts behind frontend development and am familiar with React, but I’m far from a deep expert. LLMs help me move incredibly fast when building or updating components, especially when I’m trying to match designs. I often upload screenshots of UIs or show design-implementation differences to guide the AI toward more accurate styling. More recently I’ve always tried out the &lt;a href=&quot;https://help.figma.com/hc/en-us/articles/32132100833559-Guide-to-the-Dev-Mode-MCP-Server&quot;&gt;Figma Dev Mode MCP Server&lt;/a&gt; alongside claude code and found it pretty helpful in matching designs.&lt;/p&gt;
&lt;p&gt;Having a solid understanding of the fundamentals allows me to prompt effectively, make quick corrections, and apply best practices. This workflow shines when using frameworks like Tailwind CSS. Both in my personal blog and at work, both at work and personally I use Tailwind heavily and LLMs are excellent at working with open source libraries that are well-documented and widely adopted. I was able to migrate my blog from styled-components to Tailwind in just a few hours using Cursor and some basic prompting. More recently I completely redesigned my entire blog in a single evening to give it a more modern look.&lt;/p&gt;
&lt;p&gt;These days, I can often prompt AI assistants to generate entire frontend features with minimal manual coding. It’s dramatically increased my ability to ship fullstack features quickly without needing deep frontend expertise.&lt;/p&gt;
&lt;h3&gt;Adopting New Languages and Frameworks Quickly&lt;/h3&gt;
&lt;p&gt;Before LLMs, learning a new programming language or library meant spending hours reading documentation and going through tutorials. That ramp-up time has been reduced drastically. Recently, I’ve been building features in a Python codebase using Pydantic and SQLAlchemy. While I was already familiar with Python, I hadn’t used those libraries much and yet I’ve barely had to look at the docs. A year ago, that would’ve been impossible.&lt;/p&gt;
&lt;p&gt;The hallucinations and misuse of APIs that once plagued LLMs have improved significantly (with the right models). I can now onboard to new environments with far less friction and get productive faster. On the other side LLMs are often plagued with using old/out of date dependencies and need to be prompted to check for the latest dependency to use and what documentation to look at. MCP’s like &lt;a href=&quot;https://context7.com/&quot;&gt;context7&lt;/a&gt; can help with this as well.&lt;/p&gt;
&lt;h3&gt;Debugging&lt;/h3&gt;
&lt;p&gt;While debugging is still an area with room for improvement (especially in distributed systems), LLMs have proven to be surprisingly helpful. They’re excellent at interpreting stack traces and often take me straight to the source of a problem or suggest viable fixes.
One of the most valuable superpowers here is surfacing language or framework-specific quirks that might otherwise take a human hours or days to track down through GitHub issues and scattered docs. For example, I often use LLMs to help fix specific React bugs around state updates and hooks. I will go into this a bit more later, but utilizing reasoning or thinking models for this type of work is especially important.&lt;/p&gt;
&lt;p&gt;I also use LLMs to sanity-check my fixes and think through edge cases. They can be overly agreeable, so you still need to apply critical thinking, but as a sounding board, they’re invaluable.&lt;/p&gt;
&lt;h3&gt;How I Learn Faster with LLMs&lt;/h3&gt;
&lt;p&gt;LLMs are some of the best teachers I’ve worked with. Whether I’m onboarding to a new codebase, learning a novel abstraction, or diving into a complex domain, they’ve helped me accelerate understanding dramatically.&lt;/p&gt;
&lt;p&gt;With Cursor, I often highlight snippets of code and ask for explanations, inline comments, or architectural summaries. When I want to go deeper, I switch to ChatGPT to explore broader concepts and have more nuanced back-and-forth discussions.&lt;/p&gt;
&lt;p&gt;One standout use case was learning how our C++ and OpenGL-based video rendering service works, two technologies I had little experience with. LLMs helped me get a working model of the system’s architecture quickly, which let me contribute new features in hours instead of weeks.&lt;/p&gt;
&lt;p&gt;Another was researching Advanced Substation Alpha (ASS) for a captioning feature. I used ChatGPT to dig into its syntax, styling limitations, and tradeoffs. Often running deep research threads in the background while I kept coding. This asynchronous research workflow saved days of ramp-up time.&lt;/p&gt;
&lt;h3&gt;Code Search + One-Shot Exploration&lt;/h3&gt;
&lt;p&gt;One technique I’ve been leaning into is one-shot feature exploration. Sometimes I’ll prompt an AI assistant to generate an entire feature, even if it spans 5–10+ files. I don’t expect it to work perfectly, but it helps me quickly understand scope and surface relevant parts of the codebase.&lt;/p&gt;
&lt;p&gt;I’ll usually throw the code away, but by reviewing the AI’s approach, I can break the work into smaller scoped prompts that have a higher chance of success. It’s like an accelerated form of guided spelunking.&lt;/p&gt;
&lt;p&gt;As models improve, I expect this technique to shift from exploratory to productive. Even today, it’s a huge time-saver when starting complex features. I’ve also started to see it start to work from time to time for well scoped features with the right context provided.&lt;/p&gt;
&lt;h2&gt;Tips for Getting the Most Out of AI Code Assistants&lt;/h2&gt;
&lt;p&gt;After a year of using these tools daily, I’ve developed a few techniques that consistently improve results whether I’m working on a small bugfix or a multi-file feature.
Know Some Basic Prompting Techniques&lt;/p&gt;
&lt;p&gt;I rely heavily on the chat window in Cursor and use autocomplete less often unless I’m scaffolding out some basic models/functions myself. I usually start by outlining context (briefly describing the state and linking files, directories, or images), defining the problem, making a clear ask, and appending any relevant code, logs, errors.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;
Context

Problem

Ask
---
code or logs&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I’ve tried out XML-style tags to better structure prompts when including multiple code blocks as well:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;
&amp;lt;context&gt;
...
&amp;lt;/context&gt;

&amp;lt;problem&gt;
...
&amp;lt;/problem&gt;

&amp;lt;ask&gt;
...
&amp;lt;/ask&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There is actually a &lt;a href=&quot;https://maxleiter.com/blog/rewrite-your-prompts&quot;&gt;more recent article&lt;/a&gt; highlighting how you should rewrite your prompt depending on the model. The gist of it is that OpenAI models may perform better with markdown style prompts while Anthropic models may perform better with XML style prompts. Keep this in mind depending on your model selection.&lt;/p&gt;
&lt;h3&gt;Pattern Matching, Context, and Model Selection&lt;/h3&gt;
&lt;p&gt;Most software engineering is pattern matching, and AI is no different. If you provide examples that mirror what you want, the output improves significantly. I often include relevant files and type definitions to anchor the model’s responses. This is very similar to how I’ve always coded myself looking for existing patterns or examples and using them as a starting point.&lt;/p&gt;
&lt;p&gt;Model choice also matters. I almost always manually select the model instead of using Cursor’s default. The latest Claude Sonnet model has been my go-to model for months, but recently I’ve been testing Gemini 2.5, Gemini 2.5 Pro, OpenAI’s O3, and more recently GPT-5 with good results. However I have noticed that Gemini models seem to struggle more with tool calls in Cursor than Claude models. In general I find the thinking models to behave fairly well most of the time, but the default models do often spit out garbage that requires manual intervention.&lt;/p&gt;
&lt;p&gt;This is all very relevant specifically for debugging as well as new feature development. I often use LLMs to help debug issues both in my new code and in existing production issues. Context like error messages, stack traces, and logs are incredibly helpful to LLMs as they can easily decipher the flow of code from them. A reasoning model is a must when it comes to debugging as well as it generally takes some deeper thinking. I think the other aspect of debugging with LLMs is that you should treat it the same way you would debug. For example, adding breakpoints, or logs to help add context and understand the issue feeding this context into the LLM. It’s also important to include context on what is happening i.e. what is the error state, when does it occur, and what you expect. I wrote a &lt;a href=&quot;https://boredhacking.com/seeking-help/&quot;&gt;blog post in the past on how to ask for help&lt;/a&gt; and I think this technique is essentially the same for how I ask LLMs for help debugging.&lt;/p&gt;
&lt;h3&gt;Break It Down Like You Would for a Junior Engineer&lt;/h3&gt;
&lt;p&gt;One-shotting complex features will almost never work even with really great prompts. You wouldn’t ask a junior engineer to implement type definitions, UI updates, and state logic all at once so don’t ask an AI to. Break large changes into smaller pieces, provide the right context for each step. Prompting well often mirrors good mentorship: clarity, structure, and step-by-step direction. This is very similar to most AI companies approaches today as well, agentic workflows have fairly high success rates. Free form agents though are still prone to going off the rails and needing to be reset.&lt;/p&gt;
&lt;h3&gt;Don’t Sweat the Syntax—Focus on Architecture&lt;/h3&gt;
&lt;p&gt;LLMs are powerful tools, but they can still get stuck especially when a problem requires nuance or deeper system-level understanding. I’ve had plenty of moments where I’ve gone back and forth with a coding assistant, only to realize that I needed to stop and think for myself. A quick 10–15 minute deep dive on my own often surfaces a key insight the model was missing. Once I frame that insight clearly, the assistant can suddenly resolve the issue perfectly.&lt;/p&gt;
&lt;p&gt;These breakthroughs are often the result of experience and system context, things only a human can bring. LLMs can generate and iterate, but it’s your understanding that keeps the whole process moving in the right direction.&lt;/p&gt;
&lt;p&gt;I let AI write most of the code and focus my attention on design, structure, and correctness. Reviewing AI-generated code is like reviewing a teammate’s pull request. Does it follow conventions? Is it readable? Are we duplicating existing patterns or DRYing them up?&lt;/p&gt;
&lt;p&gt;The AI helps with execution, but the thinking still has to come from you.&lt;/p&gt;
&lt;h3&gt;Reset Often&lt;/h3&gt;
&lt;p&gt;The longer a conversation thread gets, the more likely the model is to degrade in quality. I often reset chats after reaching a good checkpoint to reframe the problem cleanly. A fresh prompt usually produces better results than trying to recover from a confused thread.&lt;/p&gt;
&lt;h2&gt;Closing Thoughts: The Future of Human-AI Engineering&lt;/h2&gt;
&lt;p&gt;LLMs are changing how we build software. They’re accelerating productivity, lowering the barrier to entry for unfamiliar domains, and letting engineers focus on the things that matter most.&lt;/p&gt;
&lt;p&gt;Do I worry about my coding muscles atrophying? A bit. But I still write by hand when I need to and I apply the same level of scrutiny to AI-generated code that I would to any junior engineer. As the tools improve, the real skill will be knowing when and how to guide them. Every so often I’ll revert to more manual coding.&lt;/p&gt;
&lt;p&gt;The biggest risk right now isn’t relying on AI too much, it’s ignoring it. The engineers who learn to wield these tools with intention will move faster, learn more, and have a massive edge.&lt;/p&gt;
&lt;p&gt;I may be writing less code but I’m still designing systems, learning faster, and mentoring more effectively. That feels like progress.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[When to Build vs. Buy: A Guide for Engineers & Founders]]></title><description><![CDATA[“So should we pick the vendor or try and build it ourselves?” I distinctly remember the first time I faced that question. I had to craft an…]]></description><link>https://boredhacking.com/when-to-build-vs-buy/</link><guid isPermaLink="false">https://boredhacking.com/when-to-build-vs-buy/</guid><pubDate>Sat, 19 Apr 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;“So should we pick the vendor or try and build it ourselves?” I distinctly remember the first time I faced that question. I had to craft an answer compelling enough to win over not just myself, but my manager, his manager, and every key decision-maker in charge of our budget. Build vs Buy analysis isn’t a core engineering skill—it’s not something most engineers encounter daily. Yet, whether you’re an individual contributor, a manager, or even a founder, mastering this skill can have a lasting impact on your company’s trajectory.&lt;/p&gt;
&lt;h2&gt;Why are build vs buy decisions important?&lt;/h2&gt;
&lt;p&gt;Build vs buy decisions can shape your team’s roadmap for the coming quarters and determine how resources are allocated—whether it’s building and maintaining a new system or integrating with a third-party SaaS provider. These decisions directly affect your company’s or department’s budget, potentially limiting future investments in hiring, product development, or other critical areas. In some cases, they can serve as a key differentiator that drives product-market fit; in others, they can be the difference between staying competitive and running out of money. In the sections that follow, I’ll share how my experiences at Brex have helped me develop a repeatable framework to tackle these high-stakes decisions.&lt;/p&gt;
&lt;h2&gt;Real World Examples&lt;/h2&gt;
&lt;p&gt;Below are a series of real-world examples and the lessons I learned from multiple build vs. buy analyses at Brex. Each experience added to my understanding of making these critical decisions.&lt;/p&gt;
&lt;h3&gt;Case Study 1: Cortex for Developer Scorecards&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://www.cortex.io/&quot;&gt;Cortex&lt;/a&gt; was the first build vs. buy decision I was involved in at Brex. I was not only a core pilot implementer but also the main driver behind the decision. At the time, we were struggling to enforce best practices across our microservices for our rapidly growing team of engineers. We envisioned a scorecard—a system of best practices defined as rules—to guide our engineers when developing microservices. Initially, we estimated that building a simple system would take less than a quarter. However, we soon realized that the ongoing maintenance burden on our small team would quickly outweigh the initial build cost. Even though the upfront build estimate was roughly equivalent to paying for a third-party service, the cumulative maintenance effort and ongoing development would push the yearly cost well beyond the contract price. This taught me a crucial lesson: even if the initial development cost is low, the ongoing maintenance—and the resulting impact on focus and resources—can make a third-party solution far more attractive.&lt;/p&gt;
&lt;h3&gt;Case Study 2: DX for Developer Surveys&lt;/h3&gt;
&lt;p&gt;The next decision involved &lt;a href=&quot;https://getdx.com/&quot;&gt;DX&lt;/a&gt;, where my role shifted more towards implementing and analyzing the pilot. In this case, the ultimate decision was driven by my director of engineering and the group tech lead, based on the results of our pilot. Previously, our developer surveys yielded a 10–20% response rate, providing little actionable insight. DX changed that. Using a proprietary survey approach with automated outreach, we achieved over a 95% response rate and gathered a stack-ranked list of developers’ pain points. Although the pilot coincided with a major layoff and severe budget cuts, the quantitative data was undeniable. My director, advocating to our CTO, highlighted that the robust data from DX would significantly improve our developer experience and team performance metrics. Even though the pilot was undeniably successful in my eyes I wasn’t sure if the argument was convincing to others. However, agreeing upon what success looks like up before starting the pilot helped align leadership that investing in DX was the right move.&lt;/p&gt;
&lt;h3&gt;Case Study 3: Signadot for Iterative Development Testing&lt;/h3&gt;
&lt;p&gt;For &lt;a href=&quot;https://www.signadot.com/&quot;&gt;Signadot&lt;/a&gt;, I once again took on the role of the primary decision driver, now leading a small team. This decision was more complex. We began by aligning on the overall approach: brainstorming around ten possible solutions and grouping them by core criteria. From there, we narrowed our options to two promising approaches and split into teams to build proof-of-concepts over two weeks. Initially, our POC wasn’t even built with Signadot—we only discovered their offering during the MVP planning phase. After comparing the prototypes, we decided that a solution similar to Signadot’s was our best long-term option. We then used Signadot to develop a robust beta version of our system, which allowed us to focus on refining our core user experience. Although our initial hunch was that building such a system in-house wouldn’t be too challenging, a deeper dive into the work and potential edge cases revealed that the upfront build cost would be too high. In the end, because the solution wasn’t a core competency for us and Signadot’s pricing fit our budget, buying the solution proved to be the smarter choice.&lt;/p&gt;
&lt;h3&gt;Case Study 4: Extend for Invoice OCR&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://www.extend.app/&quot;&gt;Extend&lt;/a&gt; marked my first build vs. buy decision for Brex’s core product. A common theme across these case studies is our focus on whether a solution is a core differentiator for our company. In this instance, while one might argue that OCR could set a Bill Pay product apart, we recognized that as a fintech company, OCR isn’t a core competency. We already had multiple OCR vendors, but none delivered the performance we needed—legacy product decisions and poor accuracy were hurting our user experience. We knew we could improve things with our own product logic, but we also understood that there was an upper bound on what we could achieve in-house. When we evaluated Extend, it was not only well-priced (positioned between our two existing vendors) but also offered unmatched accuracy, flexibility, and the ability to quickly implement new features. In this case, buying from Extend was the clear choice, as it provided superior performance without diverting our focus from what we do best.&lt;/p&gt;
&lt;h2&gt;The Framework: How to perform a build vs buy analysis?&lt;/h2&gt;
&lt;p&gt;After multiple real world build vs buy decisions I was able to come to a fairly consistent framework for these types of decisions.&lt;/p&gt;
&lt;h4&gt;Define Your Requirements &amp;#x26; Document the Design&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Outline exactly what you need.&lt;/li&gt;
&lt;li&gt;Create a high-level design document that captures these requirements and estimates the work involved.&lt;/li&gt;
&lt;li&gt;This document will serve as the foundation for both building internally and evaluating external options.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Conduct Market Research&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Align on what a successful pilot looks like with stakeholders to make the decision criteria clear.&lt;/li&gt;
&lt;li&gt;Test out the product(s) with a pilot.&lt;/li&gt;
&lt;li&gt;Look at all aspects: onboarding, system integration, feature performance, and customer support.&lt;/li&gt;
&lt;li&gt;In startups, you might only have the luxury to pilot one or two providers, so choose wisely.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Run a Pilot or Proof-of-Concept&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Align on what a successful pilot looks like with stakeholders to make the decision criteria clear.&lt;/li&gt;
&lt;li&gt;Test out the product(s) with a pilot.&lt;/li&gt;
&lt;li&gt;Look at all aspects: onboarding, system integration, feature performance, and customer support.&lt;/li&gt;
&lt;li&gt;In startups, you might only have the luxury to pilot one or two providers, so choose wisely.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Estimate Internal Build Costs&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Calculate the upfront engineering cost by estimating the total hours needed, multiplied by your average engineering hourly rate (for example, $250/hour).&lt;/li&gt;
&lt;li&gt;Don’t forget to factor in ongoing maintenance, on-call support, and potential feature enhancements over time. This is something most teams drastically underestimate and should be a core aspect of any build vs buy decision&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Estimate Integration Costs for the Provider&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Create a mini design document to estimate the effort required to integrate the new service with your existing systems.&lt;/li&gt;
&lt;li&gt;Apply a similar cost estimation process as with the internal build.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Compare Total Costs Over the Contract Period&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Determine the overall cost of building internally versus buying over the entire contract period.&lt;/li&gt;
&lt;li&gt;Include all factors: upfront costs, ongoing maintenance, integration, and any variable pricing elements for the external provider.&lt;/li&gt;
&lt;li&gt;Compare these totals to make an informed decision.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Perform the Build vs Buy Decision Analysis&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Document your findings from the previous steps in a decision document to gather feedback and create alignment within your team.&lt;/li&gt;
&lt;li&gt;Consider using a structured format like SCQA (Situation, Complication, Question, Answer) for clarity.&lt;/li&gt;
&lt;li&gt;Ask the crucial question: Is this functionality core to your company? If yes, building might make more sense. If not, buying often allows you to preserve resources for your core product.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Conclusion: Making Smarter Build vs. Buy Decisions&lt;/h2&gt;
&lt;p&gt;Making a build vs. buy decision isn’t just about comparing costs—it’s about aligning with your company’s long-term goals, reducing complexity, and ensuring your team can focus on what truly matters. Through my experiences at Brex, I learned that these decisions are rarely straightforward, but by following a structured approach, you can remove much of the guesswork and make more confident choices.&lt;/p&gt;
&lt;p&gt;The biggest takeaway? &lt;strong&gt;Always consider the total cost of ownership, not just the upfront effort. The allure of building something in-house can be strong, but ongoing maintenance, operational burden, and the opportunity cost of diverting engineering time away from core initiatives can quickly tip the scales toward buying.&lt;/strong&gt; Conversely, if a capability is critical to your company’s differentiation, investing in an internal build might be the best long-term play. Brex definitely made a lot of decisions to build technology in house like our credit card processing stack which were important to our long term success and differentiation. This is now even its own product that we can provide to others via Brex Embedded.&lt;/p&gt;
&lt;p&gt;By leveraging a repeatable framework—defining requirements, researching the market, piloting solutions, and performing a rigorous cost analysis—you can make these high-stakes decisions with clarity and alignment across your team. And most importantly, you’ll avoid the trap of reinventing the wheel when a well-supported, scalable solution already exists.&lt;/p&gt;
&lt;p&gt;So, the next time you’re faced with the question, “Should we pick a vendor or build it ourselves?” you’ll have a roadmap to guide you. If this framework or these case studies resonate with you, I’d love to hear your thoughts or feedback!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Level Up Your Engineering Career with Strategic Side Projects]]></title><description><![CDATA[Why Do Side Projects Matter for Your Career Ever wondered how to stand out as a software engineer beyond what you learn on the job? Although…]]></description><link>https://boredhacking.com/software-engineering-side-projects/</link><guid isPermaLink="false">https://boredhacking.com/software-engineering-side-projects/</guid><pubDate>Wed, 29 Jan 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;Why Do Side Projects Matter for Your Career&lt;/h2&gt;
&lt;p&gt;Ever wondered how to stand out as a software engineer beyond what you learn on the job? Although many engineers go through their careers without side projects, I’ve found them invaluable for career growth and practical learning. They’ve been especially helpful for jumping into new companies, teams, and domains, as well as onboarding rapidly. Side projects are also incredibly useful if you’re working at startups, where you need to move fast and adapt often.&lt;/p&gt;
&lt;p&gt;The investments you make in side projects are compounding—the more you do them, the quicker you’ll learn and grow. While I don’t think side projects are the only reason I became a staff engineer, they’ve definitely contributed to my growth and helped me reach that level at a relatively young age. In general, side projects have allowed me to gain practical experience, stay ahead of industry trends, and prepare for new challenges that also apply to my day-to-day work. Let’s dive into the types of side projects I’ve worked on and how they’ve shaped my journey as a software engineer.&lt;/p&gt;
&lt;h2&gt;Preparing for a New Role and Rapidly Onboarding&lt;/h2&gt;
&lt;p&gt;Onboarding can be daunting. You’re learning new systems, meeting new teammates, and getting up to speed on a company’s practices. The faster you onboard, the sooner you can contribute real value—and the sooner you can continue growing as an engineer.&lt;/p&gt;
&lt;p&gt;Side projects can be a secret weapon in this process. Before starting my last two jobs, I spent time learning the languages and frameworks that the company used. During or after interviews, I’d ask what tech stack they relied on, then spin up a mini-project—like a simple blog, a to-do app, or even a mobile game—to familiarize myself with their tools.&lt;/p&gt;
&lt;p&gt;For example, at Brex, I knew I’d be working with &lt;a href=&quot;https://elixir-lang.org/&quot;&gt;Elixir&lt;/a&gt;, a language I’d heard of but never used. I spent a week or two doing tutorials and tinkering with small Elixir projects, which allowed me to commit and deploy a change on day one. Similarly, for my current job, I built a Tetris-like game in &lt;a href=&quot;https://reactnative.dev/&quot;&gt;React Native&lt;/a&gt; before I even started, so I understood the syntax, tools, and deployment process. That preparation let me jump right into the codebase on my first day.&lt;/p&gt;
&lt;h2&gt;Staying Aware of Trends&lt;/h2&gt;
&lt;p&gt;Software development is constantly evolving, and what’s popular now might change in just a few months. For staff+ engineers or aspiring founders, keeping an eye on trends is crucial for making informed decisions and avoiding outdated choices. Side projects provide a low-pressure environment to explore and learn about emerging technologies.&lt;/p&gt;
&lt;p&gt;In the JavaScript ecosystem, for instance, frameworks come and go quickly. When &lt;a href=&quot;https://nextjs.org/&quot;&gt;Next.js&lt;/a&gt; and &lt;a href=&quot;https://www.gatsbyjs.com/&quot;&gt;Gatsby&lt;/a&gt; first appeared, both promised better performance than traditional client-side &lt;a href=&quot;https://reactjs.org/&quot;&gt;React&lt;/a&gt;. At work, I chose Next.js for a project while using Gatsby to build this blog. Even though I haven’t used them professionally since then, I’ve stayed up to date through side projects. This means I know when to pick one over the other, and I can easily build quick demos with the latest versions.&lt;/p&gt;
&lt;p&gt;A more recent example is NX for monorepos. My current company uses a TypeScript monorepo but hadn’t implemented any structured framework for it. NX kept showing up in discussions and from ex-coworkers, so I decided to set up a small NX monorepo on my own. This allowed me to understand the setup, tooling, and common pitfalls, so I can help guide a future migration at work if we decide to go down that path. If you’re looking to launch a startup, being aware of (and comfortable with) new tools is often a key to moving fast and saving money.&lt;/p&gt;
&lt;h2&gt;Applying Best Practices&lt;/h2&gt;
&lt;p&gt;Testing and implementing best practices in a side project is one of the most practical ways to prepare for using them at work—without the pressure of deadlines or stakeholder expectations. You get to see what works, what doesn’t, and how to fix it when things go wrong.&lt;/p&gt;
&lt;p&gt;When I first built this blog, it used plain JavaScript with no linting, formatting, or typing tools. At work, these were always pre-configured, so I never thought much about it. Over time, though, I realized how linting and formatting reduce bugs and make code more maintainable. So I added TypeScript, Prettier, and ESLint to my personal projects. It might not sound critical for a small blog, but learning how to set it up from scratch boosted my confidence—and later helped me implement the same practices at a startup with an existing codebase.&lt;/p&gt;
&lt;p&gt;CI/CD pipelines are another area where side projects taught me a lot. Setting up &lt;a href=&quot;https://circleci.com/&quot;&gt;CircleCI&lt;/a&gt; for this blog, for instance, helped me catch issues early by validating linting, tests, and builds on every pull request. I even automated deployments to production after merges. Later, experimenting with &lt;a href=&quot;https://github.com/features/actions&quot;&gt;GitHub Actions&lt;/a&gt; gave me a broader view of CI/CD, and I could roll it out quickly at work.&lt;/p&gt;
&lt;p&gt;Refactoring is similar. I transitioned this blog from styled components to Tailwind CSS not just to keep up with trends, but also to test new workflows and tools like GitHub Copilot. Those experiences help me integrate libraries like ShadCN in other projects—and I can confidently advocate for these tools in professional environments because I’ve already worked through potential pitfalls.&lt;/p&gt;
&lt;h2&gt;Learning from Your Job&lt;/h2&gt;
&lt;p&gt;Side projects aren’t just for exploring new tools; they’re also a way to solidify lessons you learn at work. Seeing a best practice in action is one thing, but actively applying it in your own code cements your understanding and reveals nuances you might miss otherwise.&lt;/p&gt;
&lt;p&gt;At Brex, I learned the value of building apps on every pull request to avoid broken builds. Initially, I resisted because it slowed down pipelines, but after facing repeated deployment failures on my blog, I finally implemented a build validation step in my CI checks. Since then, I haven’t had a bad main build—and I’ve saved myself a ton of frustration.&lt;/p&gt;
&lt;p&gt;Brex also exposed me to the advantages of caching and parallelizing CI/CD steps. My blog’s pipeline used to run tasks like linting, testing, and building one after another, getting slower as I added more steps. Inspired by what I saw at work, I restructured my workflow to cache dependencies and run tasks in parallel, drastically reducing build times. These techniques have become staples in my professional toolkit, and I’ve brought them to other side projects and even my current company’s pipelines.&lt;/p&gt;
&lt;h2&gt;Iterating Rapidly&lt;/h2&gt;
&lt;p&gt;If you’re looking to simulate a startup environment or just want to build MVPs quickly, side projects are perfect for practicing rapid iteration, feature scoping, and building from scratch. It’s tempting—especially for newer engineers—to reach for the coolest new technology or the most performant language. However, this often complicates your project without offering much real benefit.&lt;/p&gt;
&lt;p&gt;Over the years, I’ve experimented with different technologies for quick prototypes and found a stack that lets me move fast: an &lt;a href=&quot;https://nx.dev/&quot;&gt;NX monorepo&lt;/a&gt;, &lt;a href=&quot;https://expressjs.com/&quot;&gt;Express backend&lt;/a&gt;, &lt;a href=&quot;https://nextjs.org/&quot;&gt;Next.js for web&lt;/a&gt;, &lt;a href=&quot;https://reactnative.dev/&quot;&gt;React Native for mobile&lt;/a&gt;, &lt;a href=&quot;https://www.typescriptlang.org/&quot;&gt;TypeScript everywhere&lt;/a&gt;, &lt;a href=&quot;https://tailwindcss.com/&quot;&gt;Tailwind CSS for styling&lt;/a&gt;, and &lt;a href=&quot;https://ui.shadcn.com/&quot;&gt;ShadCN for components&lt;/a&gt;. While I was slower at first, I’m now familiar enough to set up this entire environment in a few hours. That means I can shift my focus to actual features and user experience.&lt;/p&gt;
&lt;p&gt;Beyond the tools, rapid iteration teaches you how to define requirements, scope features, and break tasks into manageable pieces—skills that are essential for product engineers and founders alike. If you can quickly build an MVP, you’ll be much better at tackling larger, more complex problems down the road.&lt;/p&gt;
&lt;h2&gt;Compounding Experience and a Final Word&lt;/h2&gt;
&lt;p&gt;By focusing on targeted side projects, you not only learn new skills but also accelerate your career growth in a self-driven way. At first, it may feel challenging to find the right project or work independently without colleagues to rely on. However, the effect compounds over time, making each new project easier and more impactful.&lt;/p&gt;
&lt;p&gt;A good way to start is by following tutorials or taking courses on sites like LinkedIn Learning, Codecademy, or Egghead.io. As your confidence grows, you can piece together multiple resources, open-source documentation, and even AI tools to bring your visions to life—leading to some of the most rewarding and educational projects.&lt;/p&gt;
&lt;p&gt;Side projects might be just one piece of the career puzzle, but their compounding effect will help you move faster both professionally and personally. Whether you’re preparing for a new job, staying on top of trends, or refining best practices, these small experiments can have a big impact on your future as a software engineer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ready to start your next side project?&lt;/strong&gt; Pick one idea this week—whether it’s learning a new framework, exploring a CI/CD tool, or spinning up a mobile app—and see how quickly your skills and confidence grow.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Stop Building the Wrong Tools: How Developer Surveys Transformed Our Focus]]></title><description><![CDATA[We spent two years building an internal developer portal—only to discover it wasn’t solving our developers’ biggest pain points. Here’s how…]]></description><link>https://boredhacking.com/stop-building-the-wrong-tools/</link><guid isPermaLink="false">https://boredhacking.com/stop-building-the-wrong-tools/</guid><pubDate>Wed, 11 Sep 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;We spent two years building an internal developer portal—only to discover it wasn’t solving our developers’ biggest pain points. Here’s how a simple developer survey changed everything. As a technical lead who focused on developer productivity at a high-growth startup, I often receive inbounds from founders working on developer tooling. During these chats, I find myself reiterating this same story over and over, so I thought it might be best to write it down for others as well.&lt;/p&gt;
&lt;p&gt;No matter how many times you hear about the importance of solving real problems and talking to your customer, you don’t realize you’re doing it wrong until you’re doing it right. We spent over two years developing our own internal developer portal using Backstage, only to eventually realize it wasn’t going to solve our developers’ largest pain points at the time. By using a proper developer survey with real engagement, we were able to better understand developers’ highest priority issues and focus on the right things. Our developer productivity teams have been focusing on the right things and delivered more impact in a year than probably the previous 2 to 3 years.&lt;/p&gt;
&lt;h2&gt;The Rise of the Internal Developer Portal&lt;/h2&gt;
&lt;p&gt;In 2020, while working as a product engineer, I was approached by our platform team for an internal interview. It became clear they had a specific solution in mind—an internal developer portal. Shortly after, I joined a new team focused on building internal tools, beginning my journey in developer productivity.&lt;/p&gt;
&lt;p&gt;This team’s mandate as mentioned was to build internal developer platforms to unify our diverse set of tooling into a single interface for our rapidly growing engineering organization. Although there were a few such platforms over the years, one of our core focuses from day one was building an internal software catalog and developer portal. Over the next two years from 2020-2022, we would build an internal developer portal utilizing &lt;a href=&quot;https://backstage.io/&quot;&gt;Spotify’s Backstage&lt;/a&gt;. You can read more about that journey on the &lt;a href=&quot;https://medium.com/brexeng/backstage-adoption-at-brex-b415e0e7d3a6&quot;&gt;Brex Tech Blog&lt;/a&gt;. We were pretty early adopters of this technology, adopting Backstage when it was still in alpha, and a little ahead of the &lt;a href=&quot;https://www.gartner.com/en/documents/4010078&quot;&gt;current hype train&lt;/a&gt; for using internal developer portals. While we had many learnings along the way, the main one I always reiterate is that the software catalog itself was not a game changer for us. Our developers didn’t really need the read only functionality and software knowledge base it provided, Instead, they found the most value in our internal developer portal for specific maintenance or “write” actions like creating new pieces of software or managing their softwares deployments(releases). From 2020-2022, we spent a lot of time and resources trying to increase engagement, growing our team from two to six engineers, but we were never able to get more than 20-30% of our developers to visit it on a weekly basis.&lt;/p&gt;
&lt;p&gt;One piece of feedback that the Backstage team at Spotify often mentioned was make sure you’re solving for a real problem with your initial implementation. Internal developer portals have many different use cases and feature capabilities you can build, such as a software catalog, software creation, knowledge bases, custom functionality, user management, etc. It’s easy to try and build out a lot of this functionality right away, especially when there’s plugins to build on top of, but this increases your level of investment, delays value to developers, and adds unnecessary complexity. I myself would often echo this feedback and sentiment to those who reached out and were interested in building with Backstage, but it didn’t really click until later on.&lt;/p&gt;
&lt;h2&gt;Realizing the Gap: Implementing Internal Developer Surveys&lt;/h2&gt;
&lt;p&gt;In October 2022, after a major restructuring, our platform teams faced new resource constraints. We needed to provide more value with fewer resources—and to explicitly show that value. Right before this restructuring, we tried a developer survey tool called &lt;a href=&quot;https://getdx.com/&quot;&gt;DX&lt;/a&gt;. It promised high engagement and clear insights—something we had struggled with in our previous attempts. Not only did we get unprecedented levels of engagement (90-100% of software engineers responded), but the data itself was incredibly useful. DX comes with a predefined question set based on industry leading research into developer sentiment and productivity. It made it incredibly easy to see our top priorities according to engineers, get additional comments on the priorities, and benchmark ourselves against other companies. After our restructuring, we knew this tool would help us be laser focused on the largest pain points and showcase our value.&lt;/p&gt;
&lt;p&gt;When we reviewed the results, the message was clear: our developers’ biggest pain point wasn’t solvable via our developer portal. It was local development speed. At this point, it became clear to us that an internal developer portal wasn’t the right tool for the job, and we pivoted our focus to building local first tools for iterating on changesets.&lt;/p&gt;
&lt;h2&gt;Shifting Priorities: Putting the Developer Portal on Hold&lt;/h2&gt;
&lt;p&gt;Although we had spent the last two years heavily investing in an internal developer portal, and I myself had spent a lot of time learning about them, contributing to them, and advocating for them, it was necessary for us to divest from our internal developer portal and focus on the higher priority issues.&lt;/p&gt;
&lt;p&gt;In about 4-6 weeks we built an MVP of a new tool that would allow developers to quickly and easily run their services locally while connected to our cloud development environment to test their code alongside other services. In a single command and a few seconds, developers could validate their code changes worked alongside our hundreds of microservices. The immediate feedback was positive and we had heavy power users from day one with a rapidly growing user base. We knew we were on the right track, although there were some kinks to work out along the way – though I’ll save that for another post.&lt;/p&gt;
&lt;p&gt;Over the next few quarters we would invest more heavily into this tooling, simplifying the process and our overall local development user story based on feedback collected directly from user research as well as through the DX survey. By the end of the year we had doubled local development sentiment from 30 to 60 out of 100, achieving our reach goal, and dropped local development from the top priority to outside of the top 5.&lt;/p&gt;
&lt;h2&gt;So what now?&lt;/h2&gt;
&lt;p&gt;Hopefully this anecdote makes it clear why knowing and focusing on the right problems is so important. I often talk to startup founders who after a chat and a product demo ask if this is something Brex would be interested in. A couple of years ago, I wasn’t sure of the answer and would say maybe or let me talk to some other folks. However, after implementing an internal developer survey, the answer became simpler. If it wasn’t in the top 3 developer pain points, it was most likely not something we’d be interested in at this time.&lt;/p&gt;
&lt;p&gt;If you’re a platform or engineering organization leader and you can’t instantly say the top 3 priorities for your engineering organization, you should focus on getting answers to those questions by running a quarterly developer survey with high engagement.&lt;/p&gt;
&lt;p&gt;If you’re a founder for a developer tooling product, you should be asking companies what their developers’ top 3 priorities are and looking to solve those priorities with your tools or changing your pitch to show how you can help solve one of those priorities.&lt;/p&gt;
&lt;p&gt;While it is often important to be a few steps ahead of your developers and thinking about the future, it’s often hard at a fast moving startup to focus on anything that isn’t currently a priority. Most likely, you ain’t going to need it (YAGNI). In the end, it wasn’t about the tool we built—it was about understanding what our developers truly needed. And we wouldn’t have learned that without asking the right questions.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[From Unicorn to Decacorn: 16 Lessons Learned at Brex]]></title><description><![CDATA[I’ve spent my last four and a half years working at the then unicorn now decacorn Brex. Joining back in January of 2020 a lot has changed…]]></description><link>https://boredhacking.com/from-unicorn-to-decacorn/</link><guid isPermaLink="false">https://boredhacking.com/from-unicorn-to-decacorn/</guid><pubDate>Thu, 18 Jul 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I’ve spent my last four and a half years working at the then &lt;a href=&quot;https://techcrunch.com/2019/06/11/brex-series-c2/&quot;&gt;unicorn&lt;/a&gt; now &lt;a href=&quot;https://techcrunch.com/2022/01/11/brex-confirms-12-3b-valuation-hires-meta-exec-to-serve-as-its-chief-product-officer/&quot;&gt;decacorn&lt;/a&gt; &lt;a href=&quot;https://www.brex.com/&quot;&gt;Brex&lt;/a&gt;. Joining back in January of 2020 a lot has changed between myself, the company, and the world. Over my time at Brex, I’ve seen or experienced:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Rolling out career ladders, working towards a staff engineer promotion, and moving into management&lt;/li&gt;
&lt;li&gt;Onboarding hundreds of engineers, resulting in the growth of the company from under fifty engineers and three hundred employees to over a thousand employees&lt;/li&gt;
&lt;li&gt;Surviving three different rounds of layoffs, and countless numbers of re-organizations&lt;/li&gt;
&lt;li&gt;Moving from a product engineer helping to build and launch Brex Cash, to an internal platform tech lead focused on developer productivity for a rapidly scaling organization, back to working on product as an engineering manager helping to re-launch our Bill Pay product integrated into our expense management software&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I’ve experienced a lot of changes and growth over the last few years and written down the following learnings. A majority of these learnings I initially started writing down back in 2023, with the final few being written more recently in 2024.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Writing is important.&lt;/strong&gt; This is true for so many reasons. It allows you to share context, create consensus, process your own thoughts, learn from others via reviews, make decisions asynchronously, strategize iteratively, keep decisions for posterity, and so much more. Writing too much can however slow down and bloat decisions. To avoid this, use the right document framework/template for the type of decision.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Always be open to pivoting.&lt;/strong&gt; Of course, constant pivoting leads to thrash (which I touch on more later) but the confidence to pivot direction at any company stage is important. There have been a number of decisions at Brex that at the time seemed right but after some time became clear that they weren’t correct for the company. No matter how large Brex has gotten, the leadership team hasn’t been afraid to change direction when needed.This is a good reminder that even when you have found product market fit there are still pivots that you will need to make on your journey, and it’s important to not go down the wrong one for too long.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Transparency makes everyone feel like they’re “in the room.”&lt;/strong&gt; Early on, Brex was so transparent with employees that we would even review our P&amp;#x26;L at company wide all hands and allow folks to ask questions about it. This really allowed us to feel like everyone was in the same room when certain decisions were made. The reasoning for decisions was clear because the leadership team was honest with us on the why. While the level of transparency has decreased over the years, it’s important to note this is a privilege and it is something you need to handle with care in order to keep.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Early employees set direction.&lt;/strong&gt; Early culture and employees are the most important resource. When I joined Brex, it seemed like everyone around me was so smart and talented. There were a few engineers who I could have sworn would have been senior engineers if we had titles at the time but were only new grads out of college. As many others have probably experienced, I had imposter syndrome and felt like I was just lucky to be there. I wanted to learn from these engineers and handle the level of work they had with the same quality or even better. Early employees uplevel the next generation of talent and set the standard for delivering high quality impact.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Infrastructure can be a differentiator or detractor.&lt;/strong&gt; Brex was a fairly early mover in the corporate credit card startup space, with not a lot of platforms and SaaS offerings to pick from to build their product. While this is no longer the case today, it meant Brex had to build a lot of card payment processing infrastructure in house. Today, this is a massive differentiator for Brex because we have a direct integration with Mastercard and can build out local card issuance and acceptance that our competitors can’t. However I think a detractor that Brex suffered from early on was building too much of our internal platforms and infrastructure tooling. Our devops tooling and developer productivity tooling was very bespoke and custom, which ultimately created a larger maintenance burden for us and required teams of engineers to support. We’ve started to move away from this though and opting to buy instead of build for the right price and when it’s not a differentiator for Brex.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Company growth leads to personal growth.&lt;/strong&gt; As the company grows, issues inevitably arise. These problems create learning experiences and opportunities for the people willing and excited to work on them. These are problems that folks at other companies may never see, or may only see after working there for many years. Growth in the company generally also leads to new teams which allows you to try something new, or if you want to manage gives you opportunities to manage and grow up the manager ladder.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Say yes until you have to say no.&lt;/strong&gt; At a high growth company, there are always new challenges that come up, much faster than at other companies. For high growth individuals, these challenges open up a lot of opportunities for growth. Say yes to as many opportunities that interest you as you can. These will rapidly accelerate your career and allow you to grow outside of your team projects. However, it’s important to be aware of your bandwidth. Know your limit and learn to say no when you are fully resourced. If you don’t, you run the risk of letting down others and yourself.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The “why” is always important.&lt;/strong&gt; It should always be clear why you are proposing something and what the effect of its impact is. When challenges and problems run rampant at a fast scaling company, it’s common for people to be constantly proposing solutions. However the why and the problem are the most important thing to agree upon before jumping into solutions. Similar to starting a startup, it’s important to hone into a problem, and not create a solution in search of a problem. Spend time on defining the problem succinctly and getting alignment on the problem, its impact, and the priority of the problem.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The right idea may not be your first idea.&lt;/strong&gt; A lot of folks get stuck on their initial solution or idea and find it very hard to keep an open mind. It’s important to always make sure you’re thinking through all the tradeoffs of multiple approaches and optimizing based on what the company or team needs now. Convince yourself and others of the decision you are proposing. Utilize rubrics, decision matrices, and other frameworks to compare different solutions. Be proactive and willing to adjust your decision docs to include this information when needed. This is a good way to build alignment and settle arguments. There were many times going through this process where the conclusion changed my initial thought process.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Empathy is important both for your customers and your coworkers.&lt;/strong&gt; Just like you need to be open to the evolution of your ideas, it’s important to be open and understanding to your customers’ and teammates’ thoughts and ideas. The best employees and engineers are those who are empathetic and can put themselves in others’ shoes. Really understanding the customer and their problems leads to building the best solutions. Really understanding your peers and managers leads to building alignment and arriving at the best solution for the company, which may not always be the most “optimal” solution for another company.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Take time off so that you don’t get burnt out.&lt;/strong&gt; This is important for any company, but especially at rapid growth companies where there’s always more work than you can complete and there never seems to be a great time for vacation. For rapid growth focused people or those really bought into the company, you can often push yourself to work more and more. But it’s important to be able to step back and take time off to recharge. As in many things, it’s a marathon and not a sprint.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Moving quickly leads to more repetitions.&lt;/strong&gt; The faster you are able to move the more repetitions and practice you can get in. Your own throughput and velocity is what allows you to grow. The quicker you move, the tighter your feedback loop. The tighter your feedback loop, the quicker you can learn from your experience and mistakes. The feedback loop is critical to your growth, and not growing hurts yourself and your trust with others.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Context helps you move faster.&lt;/strong&gt; The more context you can grow, the quicker you can make decisions. Context is key. What this means is the ability to hold historical knowledge: why past decisions were made, what worked, what didn’t work, what other teams did, and why something is the way it is. The best engineers are able to gather context and hold it. They are proactive in seeing what others are doing, learning about why something is the way it is, and using this knowledge to help themselves, and others, move quicker. They need to spend less time in ideation and can quickly move to solutions when the problem is agreed upon. When teams have multiple individuals like this, they move rapidly and complex problems are quickly resolved via group effort. These teams execute rapidly and have a clear shared mission, vision, and priorities. Groups where everyone can hold a lot of context in their head are 100x teams.
2024 additions&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Keep it simple and iteratively think about the UX always.&lt;/strong&gt; “Keep it simple, stupid!” (KISS) and “you ain’t gonna need it” (YAGNI) are age old adages in software engineering. These recommendations lend themselves to building iteratively. Smart engineers, especially those from larger companies, tend to over-engineer solutions, adding complexity from the beginning. Overengineered complexity will ultimately need to be undone and require large refactors or migrations to fix later on. Starting as simply as possible and iteratively building may generate incomplete solutions, but can generally be added to iteratively instead of relying on large refactors and migrations which are more costly. Incomplete solutions are generally alright as long as you can think through the edge cases and enumerate as many known unknowns as possible which can be iteratively improved.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Good APIs &gt; platforms.&lt;/strong&gt; When people refer to platforms, most of the time they really just need good APIs. Platforms can lead to overgeneralization and complexity that once again are hard to iteratively add to. Building platforms and focusing on platformization from the onset generally lead to ideal systems in theory but rarely in practice. These systems will generally be advertised as ready to support numerous solutions, attempt to quickly onboard other teams, and often not meet the requirements. This leads to additional complexity, slower velocity, and worse developer experiences. Focus on building simple APIs with great developer and user experiences. Abstract as much complexity as possible and meet existing customers expectations. Slowly add in additional optional functionality, keeping the main UX of the API simple.&lt;/p&gt;
&lt;p&gt;After 4.5 years at Brex, my most important realization is this: &lt;strong&gt;almost everything comes down to ruthless prioritization.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It leads to better execution and quality. Having an agreed upon single list of priorities is how you ensure you are focusing your resources on the right thing and avoiding doing too much. Working on too many things at once leads to slower success and exhaustion. Everything being a priority is the death of a startup, because it can lead to overworking on the wrong things or never completing the highest priority work well enough. Quality will suffer when there are too many priorities, and quality is key to retention and avoiding churn when there are competitors in your space.&lt;/p&gt;
&lt;p&gt;Priorities should be agreed upon at every level of the organization, from the company all the way down to each team. If something isn’t on the priority list, it can’t be prioritized. If something new is added into the priority list, you can shift resources to tackle it without just adding in more work. Resources are finite and prioritization is how you use those resources wisely.&lt;/p&gt;
&lt;p&gt;The additional important thing to think through is not causing thrash by constantly changing your top priorities. Constant thrash is also death. Ultimately priority is set by product strategy which should always be clear and set on the order of 12-24 months if not longer. In addition to product strategy, there are other inputs to priorities as well to keep in mind – such as impact, customer demand as well as the size of the customers, but I won’t focus on those in this post as there’s a number of &lt;a href=&quot;https://longform.asmartbear.com/rocks-pebbles-sand/&quot;&gt;other&lt;/a&gt; &lt;a href=&quot;https://www.productplan.com/glossary/prioritization/&quot;&gt;great&lt;/a&gt; &lt;a href=&quot;https://www.productboard.com/glossary/product-prioritization-frameworks/&quot;&gt;articles&lt;/a&gt; that already go into more detail on it. Prioritize ruthlessly, and resource based on that prioritization list ensuring it is done well with a high quality.&lt;/p&gt;
&lt;p&gt;While I don’t necessarily think a lot of these ideas are novel, I’ve tried my best to succinctly write them down as they relate to my experiences. Many of these items could turn into longer blog posts in the future. Of course, these ideas may not resonate with all – just like how this type of fast paced environment isn’t meant for everyone, and should be thought through before jumping into it.&lt;/p&gt;
&lt;p&gt;Once again, I’m incredibly lucky to have gotten an opportunity to work at Brex. Working at such a fast growing company allowed me to quickly grow over these last 4.5 years and gain knowledge that may have taken quite a bit longer to cultivate. The number of problems we quickly experienced and had to solve led to many learnings and the rapid repetitions and high throughput approach allowed me to quickly practice these learnings over and over again.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Mastering the Art of Seeking Help: How Software Engineers Can Get the Perfect Answer, Faster!]]></title><description><![CDATA[Background In the fast-paced and collaborative world of software engineering, seeking help is crucial for both individual growth and project…]]></description><link>https://boredhacking.com/seeking-help/</link><guid isPermaLink="false">https://boredhacking.com/seeking-help/</guid><pubDate>Wed, 19 Jul 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;Background&lt;/h2&gt;
&lt;p&gt;In the fast-paced and collaborative world of software engineering, seeking help is crucial for both individual growth and project success. Engineers often encounter challenges that require guidance or assistance, and the effectiveness of their help-seeking approaches can significantly impact their productivity. This blog post explores the significance of effective help-seeking and the negative impact of poorly formulated questions. We will compare the outcomes of seeking help with clear context and prerequisites to the results when lacking essential information. The two main types of help-seeking scenarios we will examine are seeking assistance with unexpected output, such as errors or bugs, and seeking guidance or mentorship for specific tasks or requirements.&lt;/p&gt;
&lt;h2&gt;Types of Help Seeking&lt;/h2&gt;
&lt;h3&gt;Seeking Help with Unexpected Output (Bugs)&lt;/h3&gt;
&lt;p&gt;When faced with unexpected output, such as errors or unusual behavior from software or tools, the first step should be independent troubleshooting. Developers should conduct cursory searches externally, utilizing resources like Google and chat bots, and internally, by referring to company knowledge bases, Q&amp;#x26;A systems, and communication platforms like Slack. Often, someone else has encountered and resolved the same issue before.&lt;/p&gt;
&lt;p&gt;If self-service efforts are unsuccessful, crafting a clear and concise help request becomes essential. A well-structured help request includes the following information:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Task Description&lt;/strong&gt;: Explain the task or objective you were working on at a high level.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Action(s) Taken&lt;/strong&gt;: Detail the specific actions you attempted with the software or tool.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Error Output&lt;/strong&gt;: Share the error message or unexpected output you encountered.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Previous Attempts&lt;/strong&gt;: Include the steps you’ve already taken, links to documentation or search results you’ve explored, and any help you’ve already sought.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Before submitting the request, review it yourself, which may lead you to self-unblock or gain insights for further investigation. Once you’ve exhausted these efforts, send the request to the appropriate channel or forum. Starting with your immediate team is a good idea as someone may have encountered the issue before or have relevant context. If no one on your immediate team can help, escalating it to the owner of the domain or tool is a reasonable next step. Engage in any back-and-forth discussions, and keep others informed of any remediation progress or successful solutions. Updating relevant documentation further contributes to a supportive knowledge-sharing community.&lt;/p&gt;
&lt;p&gt;In some cases, workflows and templates are designed to gather essential information in help requests, such as GitHub issue templates in larger open-source projects or internal Slack workflows. These templates guide users to provide the necessary context for more efficient problem-solving. For instance, a typical template might include sections like description, expected behavior, actual behavior with screenshots, reproduction steps, impact, and environment details.&lt;/p&gt;
&lt;h4&gt;Hypthetical Scenario and Example&lt;/h4&gt;
&lt;p&gt;Let’s create a hypothetical scenario where a software engineer is using a command-line tool to compress a file, but encounters unexpected output in the form of an error message. Here is an example help request&lt;/p&gt;
&lt;p&gt;Subject: Help Needed - Issue with Compressing File&lt;/p&gt;
&lt;p&gt;Hi everyone,&lt;/p&gt;
&lt;p&gt;I’m using the compress CLI tool to compress a file, but I encountered an error.&lt;/p&gt;
&lt;p&gt;Task Description:
I want to compress myfile.txt to myfile.zip using the compress command with —level 10 for high compression.&lt;/p&gt;
&lt;p&gt;Action Taken:
I ran this command:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;compress --input myfile.txt --output myfile.zip --level 10&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Error Output:
Received this error:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;Error: Failed to compress file. Reason: Input file not found or inaccessible.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Previous Attempts:
I searched externally and internally but couldn’t find a solution. The file exists, and I have proper permissions.&lt;/p&gt;
&lt;p&gt;Any help to resolve this would be appreciated!&lt;/p&gt;
&lt;h3&gt;Seeking Guidance or Mentorship&lt;/h3&gt;
&lt;p&gt;The other common type of help request involves seeking guidance or mentorship to solve higher-level problems or integrate with existing software. Such requests often arise during the technical design phase of a project or while building it, requiring domain experts’ advice. A common scenario is when designing an integration within an existing software platform and needing guidance from the team that owns the underlying platform, who are domain experts. To ensure effective guidance-seeking, avoid the &lt;a href=&quot;https://xyproblem.info/&quot;&gt;“XY problem”&lt;/a&gt; pitfall, where you focus on a specific solution or roadblock without providing enough context about the underlying problem.&lt;/p&gt;
&lt;p&gt;When seeking guidance or mentorship, follow a similar approach as with unexpected output:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Problem Context&lt;/strong&gt;: Start with a high-level description of the problem you’re trying to solve, including any relevant technical or product documents.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Previous Research&lt;/strong&gt;: Mention any previous research or search efforts you’ve undertaken.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Proposed Solutions&lt;/strong&gt;: Share any solutions you’ve considered or attempted and explain your reasoning.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Roadblocks&lt;/strong&gt;: If you’ve encountered roadblocks, include them, but remember that the recommended approach might be entirely different.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Engage in discussions, make decisions on the best approach, and update the thread with your chosen path, along with any documentation updates to assist future engineers.&lt;/p&gt;
&lt;h4&gt;Hypthetical Scenario and Example&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Hypothetical Scenario:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As a software engineer, you’ve been tasked with implementing a new feature for an e-commerce platform. The requirement is to develop a “Recommended Products” section on the product detail page, which suggests related products based on the user’s browsing history. While you have some ideas on how to approach this, you’re unsure about the most efficient and scalable way to achieve it. You decide to seek guidance from more experienced developers to ensure you’re on the right track.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example Help Request:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Subject: Seeking Guidance - Implementing “Recommended Products” Feature&lt;/p&gt;
&lt;p&gt;Hello everyone,&lt;/p&gt;
&lt;p&gt;I’m working on implementing a “Recommended Products” feature for our e-commerce platform and could use some guidance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Problem Context:&lt;/strong&gt;
The task is to create a section on the product detail page that displays recommended products to users based on their browsing history. We want to enhance the user experience by suggesting relevant items that align with their interests.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Research:&lt;/strong&gt;
I’ve done some initial research both externally and internally to explore different approaches. While I found some general strategies for recommendation systems, I’m unsure which method would be the most suitable for our platform’s scale and user base.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposed Solutions:&lt;/strong&gt;
I’m considering two potential approaches:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Collaborative Filtering: Using user history and behavior to recommend products based on similar users’ preferences.&lt;/li&gt;
&lt;li&gt;Content-Based Filtering: Analyzing product attributes and metadata to suggest items with similar characteristics.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Roadblocks:&lt;/strong&gt;
I’m concerned that my proposed solutions might not be the most efficient or effective for our specific use case. Additionally, I’m unsure about the data processing and storage requirements for implementing these recommendation strategies.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Help Needed:&lt;/strong&gt;
I would greatly appreciate your insights on the best approach for our “Recommended Products” feature. Which method do you think would be more suitable for our platform? Are there any other recommendation algorithms or strategies I should consider? Additionally, if you have any tips on data processing and storage for handling a large number of users and products, that would be incredibly helpful.&lt;/p&gt;
&lt;p&gt;Once we decide on the approach, I’ll proceed with the implementation and keep you updated on the progress.&lt;/p&gt;
&lt;p&gt;Thank you for your time and expertise!&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Mastering the art of seeking help is a crucial skill for software engineers. Providing clear context and prerequisites when asking questions leads to more efficient problem-solving and fosters a positive, supportive, and successful community. By following the best practices outlined in this blog post, engineers can unblock themselves, receive faster and more accurate assistance, and contribute to a thriving knowledge-sharing ecosystem. Empowered with these skills, engineers can confidently tackle challenges, make meaningful progress in their projects, and collectively drive innovation in the world of software development.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kubernetes Oops to Kubernetes Ops: Mistakes, Learnings, and Improved Practices]]></title><description><![CDATA[In my first professional experience with Kubernetes (K8s), I was tasked with improving our ecommerce store site performance and SEO. We…]]></description><link>https://boredhacking.com/kubernetes-oops-to-kubernetes-ops/</link><guid isPermaLink="false">https://boredhacking.com/kubernetes-oops-to-kubernetes-ops/</guid><pubDate>Sat, 01 Jul 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In my first professional experience with &lt;a href=&quot;https://kubernetes.io/&quot;&gt;Kubernetes (K8s)&lt;/a&gt;, I was tasked with improving our ecommerce store site performance and SEO. We decided to migrate our React single-page app from client-side rendering to server-side rendering, gradually migrating pages and routing traffic dynamically using a reverse proxy. To deploy the new applications, we explored containerization and chose &lt;a href=&quot;https://aws.amazon.com/eks/&quot;&gt;AWS’s Elastic Kubernetes Service (EKS)&lt;/a&gt; for hosting via Kubernetes.&lt;/p&gt;
&lt;p&gt;Looking back, I made several mistakes due to my limited understanding and inexperience with both the technology and mature cloud deployment processes. Coupling multiple new technologies into a single project was my first mistake, as it added complexity to the implementation, maintenance, and team onboarding. Additionally, some mistakes were a result of misinformation or outdated information since EKS and Kubernetes were relatively new in 2018.&lt;/p&gt;
&lt;p&gt;During this time, I documented my journey through blog posts, hoping to help others facing similar challenges. However, I now question whether I unintentionally spread misinformation instead of providing accurate guidance.&lt;/p&gt;
&lt;p&gt;My initial mistakes revolved around setting up the architecture of our Kubernetes clusters. While I understood the importance of having separate staging and production environments, I wrongly set up a separate cluster for each deployment. We had a staging and production cluster for both the React app and the reverse proxy, totaling four clusters. In retrospect, there were better approaches, such as utilizing separate clusters for for each environment that housed all the deployments(one for staging and one for production). This would have provided a simpler starting point, had I better under the concepts of containerized workloads and orchestration platforms.&lt;/p&gt;
&lt;p&gt;As a newcomer to Docker and containerization, my first step was learning how to build a Next.js Docker container and publish it to AWS ECR, as explained in &lt;a href=&quot;/next-js-docker-ecr&quot;&gt;Setting Up a Next.js Docker Container and Publishing it to AWS ECR&lt;/a&gt;. Fortunately, this process was straightforward and hard to mess up.&lt;/p&gt;
&lt;p&gt;In &lt;a href=&quot;/deploying-to-eks-codeship&quot;&gt;Deploying a New Docker Image to an EKS Cluster on Codeship&lt;/a&gt;, I discussed our automated CI/CD pipeline for deploying changes to our staging cluster. However, our method of rolling out application changes to Kubernetes was flawed. I had a limited understanding of Kubernetes resource files and only used them for initial setup, neglecting to update or use them as templates. Instead, we relied on environment variables set in the Docker container during build time. Our deployment approach involved using the kubectl set image command to update a deployment’s container image as a patch, which had drawbacks such as the lack of version control and limitations in the deployment workflow. In subsequent sections, I will share iterative learnings and improvements for deploying changes. Another significant area of naivety in our Kubernetes clusters was the lack of observability, as we hadn’t set up logging or APM infrastructure, relying solely on pod logs and CloudWatch.&lt;/p&gt;
&lt;p&gt;One positive aspect of my initial experience with Kubernetes was the use of &lt;a href=&quot;https://eksctl.io/&quot;&gt;eksctl&lt;/a&gt;, a tool by &lt;a href=&quot;https://www.weave.works/&quot;&gt;Weaveworks&lt;/a&gt;, which saved us time and ensured the correct initial setup and configuration of our Kubernetes clusters. I discussed this tool in &lt;a href=&quot;/setup-and-deployment-on-eks&quot;&gt;Setting Up AWS Elastic Kubernetes Service (EKS) and Deploying&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Intermediate level&lt;/h2&gt;
&lt;p&gt;After my initial Kubernetes journey, I joined a very early-stage startup where I was the sole engineer. In hindsight, I made the naive decision to introduce Kubernetes as our initial method for running applications in the cloud. Considering the scale and requirements of the startup, starting with something simpler like Elastic Container Service would have sufficed, as we only had a few microservices.&lt;/p&gt;
&lt;p&gt;Fortunately, we enlisted the help of a software consultancy company to augment our team and expedite product development. The consultancy’s DevOps department had more expertise in Kubernetes and assisted in setting up our initial CI/CD pipelines, imparting valuable knowledge along the way.&lt;/p&gt;
&lt;p&gt;Firstly, they guided us in establishing a more appropriate Kubernetes architecture using well-scoped namespaces to separate environments, such as staging and production. While further fault tolerance and isolation could have been achieved by separating environments into clusters, it wasn’t necessary given our small scale.&lt;/p&gt;
&lt;p&gt;The next significant learning point revolved around leveraging Kubernetes resource templates. Instead of using the kubectl set image command to update deployments, the consultancy introduced Kubernetes templates that our CI/CD pipeline would update and apply to deploy changes. They used a simple tool called sed to replace values in the templates. However, we could have further improved this process by utilizing open-source tools specifically designed for managing Kubernetes templates. &lt;a href=&quot;https://helm.sh/&quot;&gt;Helm&lt;/a&gt;, a popular project for managing Kuberentes packages and templating Kubernetes resources, could have been an excellent choice.&lt;/p&gt;
&lt;p&gt;Lastly, the consultancy provided guidance on setting up open-source observability tools on Kubernetes. We implemented &lt;a href=&quot;https://prometheus.io/&quot;&gt;Prometheus&lt;/a&gt; and &lt;a href=&quot;https://grafana.com/&quot;&gt;Grafana&lt;/a&gt; to monitor application health metrics through a dashboard. We explored both &lt;a href=&quot;https://grafana.com/oss/loki/&quot;&gt;Loki&lt;/a&gt; and &lt;a href=&quot;https://www.graylog.org/products/source-available/&quot;&gt;Graylog&lt;/a&gt; for logging tools in Kubernetes and ultimately chose Graylog due to Loki’s limited functionality at the time. It’s worth noting that Loki has since made significant advancements and may now serve as a suitable built-in logging tool integrated with Grafana.&lt;/p&gt;
&lt;p&gt;In general, by seeking guidance from experts, I was able to avoid many issues during this phase. However, there was still much to learn, additional tools to explore, and room for further improvements.&lt;/p&gt;
&lt;h2&gt;Maturity&lt;/h2&gt;
&lt;p&gt;Lastly, I want to share my recent learnings from working at my current company, Brex. When I joined in January 2020, Brex already had a Foundation organization consisting of multiple teams responsible for maintaining our build and release process, as well as our cloud infrastructure, including multiple Kubernetes clusters. In January 2021, I transitioned into this organization and gained invaluable knowledge from my experienced colleagues, particularly regarding software releases and Kubernetes cluster management.&lt;/p&gt;
&lt;p&gt;Initially, we used Helm to template and create new releases for each microservice’s Kubernetes resources. We would then utilize our custom deployment manager to apply updated Helm charts to the cluster and roll out changes. However, we eventually transitioned to a &lt;a href=&quot;https://www.redhat.com/en/topics/devops/what-is-gitops#:~:text=GitOps%20uses%20Git%20repositories%20as,set%20for%20the%20application%20framework.&quot;&gt;GitOps&lt;/a&gt; approach, leveraging the &lt;a href=&quot;https://fluxcd.io/&quot;&gt;Flux&lt;/a&gt; open-source project. GitOps allows us to easily track and reproduce the cluster’s current state by maintaining all Kubernetes resources in a Git repository. This repository serves as the single source of truth for our Kubernetes cluster, and Flux operators continuously monitor the repository for updates, automatically reconciling and applying changes to the cluster. This approach provides better visibility into the expected state of the cluster and facilitates troubleshooting any discrepancies between the GitOps state and the cluster state. It’s worth noting that while we no longer rely on Helm for the GitOps approach, we still utilize its templating engine. Our CI/CD process generates finalized Kubernetes resources and Flux-compliant Kustomizations, which are then managed by another custom release management service.&lt;/p&gt;
&lt;p&gt;Once again, learning from knowledgeable teammates and collaborating on these systems has been immensely valuable. I’ve gained significant insights from our build platform, release platform, and cloud infrastructure teams, who continuously enhance the maturity of our clusters. The rapid growth of the company and its underlying infrastructure has contributed to my own professional growth and expanded expertise.&lt;/p&gt;
&lt;h2&gt;Retrospective&lt;/h2&gt;
&lt;p&gt;Reflecting on these learnings, if I were starting a new company, I would likely reconsider using Kubernetes initially, despite my current comfort with it. There are simpler services like &lt;a href=&quot;https://aws.amazon.com/ecs/&quot;&gt;Amazon Elastic Container Service (ECS)&lt;/a&gt; for deploying containerized workflows on AWS. The cognitive overhead for developers to run their software on Kubernetes has been an important realization. Most developers may not possess the knowledge or time to fully understand the intricacies of Kubernetes. For smaller companies without the necessary resources to abstract and maintain these systems, it could potentially slow down developers or introduce unnecessary issues. However, as a company scales and has multiple software projects to deploy, Kubernetes becomes a suitable choice because of its ability to leverage platform characteristics across all applications.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Staff Engineer: To be or not to be?]]></title><description><![CDATA[In February 2022, I achieved a significant milestone in my career by being promoted to Staff Engineer at Brex. As I settled into this new…]]></description><link>https://boredhacking.com/staff-engineer-to-be-or-not-to-be/</link><guid isPermaLink="false">https://boredhacking.com/staff-engineer-to-be-or-not-to-be/</guid><pubDate>Sun, 23 Apr 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In February 2022, I achieved a significant milestone in my career by being promoted to Staff Engineer at Brex. As I settled into this new role, I began to receive a lot of questions from engineers who were contemplating whether or not to pursue the same career path. Their inquiries were along the lines of “Is it worth it to become a staff engineer?” or “Should I work towards becoming a staff engineer?“. While I initially struggled to answer these nuanced questions in person, I have spent the past year reflecting on my own motivations for pursuing this role, the work and effort I invested to get here, and my thoughts on the role after a year of experience. In this post, I will share my personal journey, hoping that my own experience can help answer these common questions in a more meaningful and personalized way.&lt;/p&gt;
&lt;h2&gt;My Motivations for Becoming a Staff Engineer&lt;/h2&gt;
&lt;p&gt;I’ve held a few different software engineering roles in my relatively short career, including working at a small startup with around 5 full-time engineers, being the first full-time engineer at a pre-seed startup, and working as an engineer at Brex which is the largest and fastest-growing company I’ve worked at.&lt;/p&gt;
&lt;p&gt;As an engineer at Brex, I’ve enjoyed designing, leading, and managing projects of varying sizes, as well as contributing to larger engineering-wide initiatives, such as improving recruitment processes or important internal documentation. However, over time, I found myself feeling limited by the senior engineering role. While I enjoyed coding and solving technical problems, I wanted to have more influence, impact, and scope in my work.&lt;/p&gt;
&lt;p&gt;I found fulfillment in working on larger initiatives, both technical and non-technical, and in proposing new projects and mentoring others. I wanted to improve my influence and impact, which I saw as key characteristics of the staff engineer role at Brex.&lt;/p&gt;
&lt;p&gt;Moreover, becoming a staff engineer would allow me to have more project opportunities, including identifying, proposing, and leading larger projects with multiple engineers. As a staff engineer, I could push to prioritize projects that I identified and thought aligned with the team’s goals. I also wanted to be able to lead large projects with multiple other engineers or teams, as I enjoyed both collaborating and mentoring.&lt;/p&gt;
&lt;p&gt;Ultimately, I realized that becoming a staff engineer would give me more opportunities to do more of the work that I found fulfilling and would allow me to have a greater impact and influence in the company. However, I knew that getting to this role would require effort and work on my part, as well as support from my manager and others.&lt;/p&gt;
&lt;h2&gt;Working Towards the Staff Engineer Role: My Experience and Tips&lt;/h2&gt;
&lt;p&gt;I believe working towards the staff engineering role is a deliberate choice that requires a significant commitment. While some individuals may have their managers proactively push for their promotion based on their existing work, most have to actively pursue it. I also think it’s generally important to make this a deliberate choice to ensure your ongoing success in the role as it’s often one of the hardest roles to meet expectations in. There is no clear or single path to becoming a staff engineer, but it generally involves finding opportunities and projects to demonstrate staff scope and impact, exceeding expectations in your current role, and collaborating with other engineers and non-engineers across the company.&lt;/p&gt;
&lt;p&gt;One approach to working towards the staff engineering role is to have a clear career development plan in place. This can include maintaining a career log to track past and ongoing work, initiatives, proposals, and goals. It is important to communicate this plan to your manager and align on what you are currently working on, what you could be working on, and what other opportunities exist. Constantly evaluating your ongoing projects, additional commitments and future commitments can help ensure that you prioritize the most impactful work and have a plan for what to work on next before you finish the current set of work.&lt;/p&gt;
&lt;p&gt;Collaborating and working with others across the company is also critical to the staff engineering role. This can involve working on special initiatives, identifying work for other teams, and mentoring other teams on your platforms/domains. It is essential to grow your collaboration skills to know how to work with others, uplevel them, align with them, and know who to communicate with in certain situations. It can also help showcase you as a functional expertise in one or more systems. Moreover, additional voices who can vouch for you during the promotion review process can be valuable.&lt;/p&gt;
&lt;p&gt;As you work towards becoming a staff engineer, it is essential to continuously align with your manager to assess how you are performing, identify what is missing, and find ways to improve constantly. This means finding opportunities to demonstrate staff scope and impact while still exceeding expectations in your current role by designing and developing your work, mentoring your direct teammates, etc.&lt;/p&gt;
&lt;p&gt;Finally, it is essential to note that the path to becoming a staff engineer is not linear, and it may take years to achieve this role. However, by developing a clear career development plan, collaborating with others, and continuously aligning with your manager, you can work towards achieving this goal.&lt;/p&gt;
&lt;h2&gt;Reflecting on the Challenges and Changes of Advancing to the Staff Engineering Role&lt;/h2&gt;
&lt;p&gt;Reflecting on the past year in a staff engineer role, I’ve learned that the work is indeed different from what it was before. As everyone says, the expectations are much higher, and it’s not just about thinking of your own work anymore, but that of others on your teams and other teams as well. Although you’re not always in the room, you’re definitely in more rooms. It’s also crucial to be aware of the various archetypes you can fluctuate between depending on the organization’s needs. It’s important to align with your manager(s) and ensure you’re meeting expectations and doing what’s expected of you at any given time. Being successful in this role can often involve learning how to properly manage up.&lt;/p&gt;
&lt;p&gt;However, exceeding and progressing beyond the staff role is even less clear than getting to the staff role itself. Expectations vary depending on the company, and it’s easy to get lost in too much high-level technical leadership and not enough hands-on development or vice versa. Striking the right balance between these two areas and being deliberate with your work choices is critical. Ultimately, reflecting on the past year has taught me the importance of being adaptable, collaborative, and constantly learning and growing as a staff engineer.&lt;/p&gt;
&lt;p&gt;All in all I think answering the question whether or not the staff+ role is right for you is a personal decision that depends not only on your own career goals and skills but also the expectations of the role at your company. I have found it helpful reading and hearing about the experience from others and hope this post helps other engineers in the decision making process of pursuing the staff+ role.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Initial Thoughts on Github Actions]]></title><description><![CDATA[Background Although over the years I’ve used different continuous integration and deployment(CICD) and workflow automation tooling at my…]]></description><link>https://boredhacking.com/initial-thoughts-github-actions/</link><guid isPermaLink="false">https://boredhacking.com/initial-thoughts-github-actions/</guid><pubDate>Tue, 14 Feb 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;Background&lt;/h1&gt;
&lt;p&gt;Although over the years I’ve used different continuous integration and deployment(CICD) and workflow automation tooling at my places of work, I’ve mostly used &lt;a href=&quot;https://circleci.com/&quot;&gt;CircleCI&lt;/a&gt; as my personal project CICD framework/service. This was initially because CircleCI had a free tier and was easy to use. In general I haven’t had any real issues with CircleCI, it’s worked well for my small side projects but its free tier is only valid on public repos. This limits the projects you can utilize it for without paying for the service. It’s also important to note that when I initially started using CircleCI, Github Actions didn’t exist as it was launched in late 2018. In December of 2022, I was working on a new side project that I didn’t want to make public and thought it would be a good chance to check out Github Actions and investigate it for future uses. This post will go into some of my initial thoughts and impressions of github actions. Please note that I’ve only used it for fairly trivial things like deploying a React app to AWS s3.&lt;/p&gt;
&lt;h2&gt;Lots of Open Source Actions&lt;/h2&gt;
&lt;p&gt;First off Github has an entire &lt;a href=&quot;https://github.com/marketplace?type=actions&quot;&gt;marketplace&lt;/a&gt; of open source github actions that you can easily pull into your project. This makes it super easy to get up and running with common workflows for small applications. So for folks looking for easy to setup CICD for side projects github actions make a lot of sense.&lt;/p&gt;
&lt;h2&gt;Free Tier for Private Repos&lt;/h2&gt;
&lt;p&gt;Free tiers are super important for side projects. In general, folks just want to hack things together and learn. Having to pay for services stifles learning because it creates a barrier for entry. Although I can definitely afford paying for small services for my own side projects this is not always true for others. Even if you can pay to host and maintain your side project, it can still stifle learning because of additional setup to hook up a credit card and create payments. CircleCI was my initial choice for side project CICD because of their generous free tier. However, they only allow their free tier to be utilized by public repos. Although most of my side projects have no issues being public, that isn’t always the case and I have chosen to avoid certain projects where I’d rather not publicly display the code.&lt;/p&gt;
&lt;p&gt;However, this is no longer the case with Github Actions! You can check out their &lt;a href=&quot;https://github.com/pricing&quot;&gt;pricing&lt;/a&gt; online but the TLDR is that you get 2000 CI/CD minutes per month for private repos via Github Actions (and free for public repositories). This is a great feature of Github Actions which make them a super easy choice for adoption when utilizing Github to host your code.&lt;/p&gt;
&lt;h2&gt;Black Box and Lack of In Depth Examples&lt;/h2&gt;
&lt;p&gt;There are a couple of issues though that I noticed with Github Actions (at least from my perspective). The first is that the giant open source marketplace creates a black box effect. In general unless you go in and read the code of the actions, the action’s implementation is hidden from you. And even if you do go and read the github actions it may utilize other open source actions creating a nested set of black boxes that you need to slowly unravel. In general other CICD platforms also have open source/premade plugins you can pull into your CICD workflows, however Github Actions have automated almost every potential command invocation/workflow for simple apps. Generally other CICD platforms will show examples where you can more easily understand the flow because you are still invoking the same commands in your workflow that you would locally. Github Actions have abstracted even lots of these basic commands which makes it a lot harder to understand everything that is going on.&lt;/p&gt;
&lt;p&gt;Furthermore, there are little to no in-depth examples of implementing some of these basic workflows yourself. Instead the &lt;a href=&quot;https://docs.github.com/en/actions/examples/using-scripts-to-test-your-code-on-a-runner&quot;&gt;examples&lt;/a&gt; are overall lacking and use the open source actions greatly leading to more confusion. This makes it very hard to write your own github actions using non open source actions. An improvement here would be more detailed documentation to write github actions yourself utilizing the native commands you would use locally.&lt;/p&gt;
&lt;p&gt;That being said this may not be an issue for everyone, some folks may enjoy the black box abstraction that allows them to not worry about the underlying implementation.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Areas of Improvement for Elixir]]></title><description><![CDATA[Disclaimer I’d like to start off by stating that this blog post is my own thoughts. It does not reflect the ideas and thoughts of Brex. You…]]></description><link>https://boredhacking.com/areas-of-improvement-for-elixir/</link><guid isPermaLink="false">https://boredhacking.com/areas-of-improvement-for-elixir/</guid><pubDate>Mon, 13 Feb 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;I’d like to start off by stating that this blog post is my own thoughts. It does not reflect the ideas and thoughts of Brex. You can read more about Brex’s decision in this &lt;a href=&quot;https://medium.com/brexeng/building-backend-services-with-kotlin-7c8410795e4b&quot;&gt;engineering blog post&lt;/a&gt; by Pratik Tandel. That being said, some of what I’m about to talk about will echo the other blog post.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;As I’ve mentioned on this &lt;a href=&quot;/one-year-of-elixir&quot;&gt;blog previously&lt;/a&gt;, I’ve worked in Ruby prior to joining Brex and really enjoyed the experience so I was excited to learn Elixir. Even before joining I took some time to play around with and learn the language so I could hit the ground running. Prior to my professional career, I took a course in college entitled “Data Structures and Functional Programming” where we learned about functional programming concepts while coding in OCaml. So even before Elixir I had some experience with functional languages and rather enjoyed the different programming paradigm and thought process.&lt;/p&gt;
&lt;p&gt;While at Brex, I was a member of a volunteer team dedicated to maintaining Elixir libraries and documentation as well as onboarding and upleveling engineers in Elixir. I developed and led an onboarding class around Elixir general information and Brex custom Elixir knowledge which was given to hundreds of onboarded engineers. While I no longer get to code in Elixir in my day to day work at Brex, I always enjoyed programming in it and wanted it to be loved and enjoyed by others.&lt;/p&gt;
&lt;p&gt;Nevertheless, it’s been about two years since my last active Elixir development at Brex. Since then I have reflected back on some of the shortcomings of the language and our guidance around it. I touched on some of this in my previous post on &lt;a href=&quot;/elixir-learnings-and-hiring&quot;&gt;Elixir Learnings and Hiring&lt;/a&gt; but will try to cover some new topics. I hope this post can be utilized by the community and other adopters to ensure Elixir’s future success.&lt;/p&gt;
&lt;h2&gt;The Shortcomings&lt;/h2&gt;
&lt;p&gt;Although there were many reasons &lt;a href=&quot;https://medium.com/brexeng/why-brex-chose-elixir-fe1a4f313195&quot;&gt;why Brex initially chose Elixir&lt;/a&gt;, over time there were also a number of issues that ended up slowing us down. The following are some of my observations on our shortcomings while using Elixir. Not all of these are issues with the language itself but rather issues with our use, guidelines, or lack thereof.&lt;/p&gt;
&lt;h3&gt;Lack of Static Typing&lt;/h3&gt;
&lt;p&gt;There are lots of arguments for both dynamic and static typing. I won’t be going into detail on all of the merits of each, but instead I’ll focus on the shortcoming that a lack of static typing presents for us. Early on in a product development lifecycle dynamic typing allows you to iterate quickly by reducing the amount of code you need to write. But as you scale your codebase and your engineering team it can start to slow you down. Engineers have a harder time understanding code because the types of parameters or variables are not explicit and can take some time to trace. There are also a whole domain of bugs that can be avoided via static typing. Although tools like &lt;a href=&quot;https://github.com/jeremyjh/dialyxir&quot;&gt;Dialyxir&lt;/a&gt; can be used to perform static analysis and catch type definition issues in Elixir, it still requires you to define typespecs for your code. It is also quite easy for a team or project to be started without Dialyxir. If you skip out on static analysis of types early on and the codebase grows quite large then it will require a large effort to implement static type analysis fully to make it useful. One thing that definitely could have alleviated this issue for us a bit would have been utilizing typespecs and Dialyxir earlier on and enforcing their use. However the overall lack of static typing is hard to overcome completely and leads to the next shortcoming.&lt;/p&gt;
&lt;h3&gt;IDE experience&lt;/h3&gt;
&lt;p&gt;As we onboarded more and more engineers a consistent complaint that came up with Elixir was the IDE experience. Developers coming from statically/well typed languages were used to a rich IDE experience with things like full autocomplete and easy refactoring to mention a couple. Our recommendation at the time was to use VS Code alongside the &lt;a href=&quot;https://github.com/elixir-lsp/elixir-ls&quot;&gt;Elixir language server&lt;/a&gt; which although is a pleasant experience for most is definitely not comparable to the full IDE experience of a statically typed language. It’s also worth noting that if we had used typespecs and Dialyxir we probably would have improved the experience. Another potential issue is that we used docker containers for local development so engineers did not always have their local machine setup properly to utilize Elixir tooling fully locally. Something we could have attempted to devote more time to would have been ensuring a well documented IDE setup and local tooling setup, as well as potentially creating plugins or additional tooling for this local IDE setup.&lt;/p&gt;
&lt;h3&gt;Dwindling Internal Support and Maintenance&lt;/h3&gt;
&lt;p&gt;Fairly early on Brex established a team that devoted a lot of effort to building internal Elixir libraries and speeding up developer productivity through shared “systems”. However over time the focus of this team moved away from Elixir specific improvements and more so to building and maintaining shared systems such as an asynchronous event processing system. This left Elixir in a precarious position because no team was focused on its support and maintenance. Eventually we did create a virtual team of volunteers to attempt to take over support and maintenance but these engineers were on separate teams with other projects and focuses. It was not easy for them to prioritize larger Elixir work on top of their massive project load at a fast moving startup. Therefore Elixir and its libraries slowly degraded. Our Elixir version and Erlang versions became stationary at 1.8.1 and 22 respectively, which held us back from taking advantage of faster compilation and further improvements to the language. Similarly library dependencies were not upgraded, and internal libraries, documentation, and tooling were not maintained as they did not have clear ownership. Without dedicated owners the internal Elixir ecosystem became unmaintained.&lt;/p&gt;
&lt;h3&gt;Tooling Integration and Build System&lt;/h3&gt;
&lt;p&gt;The last topic I’m going to cover is around Elixir’s integration with other tools and its build system. First let’s start off with a little context. At Brex we utilize a monorepo. Initially this monorepo had an Elixir umbrella app but we moved away from an umbrella to separate Elixir apps. We utilize &lt;a href=&quot;https://grpc.io/&quot;&gt;gRPC&lt;/a&gt; with &lt;a href=&quot;https://developers.google.com/protocol-buffers&quot;&gt;Protocol Buffers&lt;/a&gt; for interservice communication between our microservices, although this wasn’t always true. Lastly we utilize &lt;a href=&quot;https://bazel.build/&quot;&gt;Bazel&lt;/a&gt; to build our applications within our monorepo, across multiple languages (for various reasons we have had some applications in python, typescript, and golang even before migrating to Kotlin).&lt;/p&gt;
&lt;p&gt;In general Elixir’s tooling is fairly great in isolation. Mix works well for managing dependencies, building, and testing your Elixir apps, but due to a variety of issues mix eventually became very slow to build some of our larger applications and in general could not produce reproducible builds. A couple of these reasons were due to us not upgrading Elixir/Erlang to take advantage of compiler optimizations as well as how we structured our protobuf elixir generated code as a single massive library.
There were two larger issues we encountered around the Elixir ecosystem integrating with our other tools. The first was around the lack of maturity in the &lt;a href=&quot;https://github.com/elixir-protobuf/protobuf&quot;&gt;elixir-protobuf&lt;/a&gt; library at the time (2 years ago) where it was originally only maintained by a single person. We ended up deciding to fork the elixir-protobuf library in order to implement some functionality we wished for, which made it harder to keep up to date with the upstream version. However, over the last two years Tubi and Community have sponsored the project and increased overall functionality and support of the library which is great!&lt;/p&gt;
&lt;p&gt;The second large issue we ran into was around the lack of open source support for building Elixir with Bazel. In general Bazel relies on there being a defined set of rules to know how to build artifacts for different platforms/languages. For many mainstream languages there are already predefined rulesets maintained by a community or company, you can see lots of them in the&lt;a href=&quot;https://github.com/orgs/bazelbuild/repositories?q=&amp;#x26;type=all&amp;#x26;language=&amp;#x26;sort=&quot;&gt;bazelbuild&lt;/a&gt; github org such as java, python, rust, nodejs, c++, etc. However as far as I’m aware, there is still to this day no open source set of Bazel rules for Elixir and as recent as Sept 2022 this was brought up on the &lt;a href=&quot;https://elixirforum.com/t/elixir-and-bazel-google-s-open-sourced-monorepo-build-system/50345&quot;&gt;Elixir forum&lt;/a&gt;. In order to get around this issue we worked on an initial somewhat hacky version of rules for elixir which did not follow Bazel best practices, without getting into too much detail we dynamically generated build targets and directives in CICD as opposed to statically defining BUILD.bazel files and checking them in alongside our source code. This has meant that developers cannot utilize Bazel for local development flows like they can for every other language at Brex. Leading to developers remaining to use mix for Elixir and not able to take advantage of any Bazel build optimizations or tooling. Over the last year or so there has been an internal push though to improve our internal Elixir bazel rules so that we can get Elixir to a state where bazel files are checked into source code and bazel can be used for building and testing by developers as it is with other languages at Brex.&lt;/p&gt;
&lt;h2&gt;What can we do?&lt;/h2&gt;
&lt;p&gt;So we’ve gone over a bunch of shortcomings we encountered, but what can be done? In general as I’ve already stated, I’m not here to say Elixir will never succeed at a large company. You can already see on the &lt;a href=&quot;https://elixir-lang.org/cases.html&quot;&gt;Elixir website&lt;/a&gt; a list of case studies of both startups and larger organizations adopting Elixir for different reasons and use cases. However, I do think that a part of what’s missing from Elixir is larger company sponsorship and presence. If we look at the &lt;a href=&quot;https://survey.stackoverflow.co/2022/#technology&quot;&gt;Stack Overflow 2022 Developer Survey&lt;/a&gt; results we can see that Elixir is clearly a loved language by those who use it coming in at number 2 even above typescript! And I echo the sentiment that Elixir is one of my favorite languages I’ve programmed in.
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; &quot;
    &gt;
      &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 59.45945945945946%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAABYlAAAWJQFJUiTwAAACAklEQVQoz5VTTXPSUBTlV1SdqUoJ30ETGkpaCigJQSBOA0VIWmTamY512nFcuHBcuG2rXbrza1w4lvAPHB3wpx3vfQGpU63j4uTde/Ny3jn33YSWMlXE1DoSy02BIG4glq0jTmtiini2IXLpdg2RW9YFcP1m2kCICdX1NgrVLeiVHvJ3u1ituFg1XOTvdEVNp3zN3ELR6iNBxGHZBH/HCMtVQcZCbqQqCPFLpdCCVu5AK3WQKz8QK+c5rlEefDgn+RuEQn6oRKisOUjlmkjnbKRX7lNsi5it/ovoAuFycRPFqkdWeyiwVbLNYLtJrfl/hEuygcVMDVcyFhbSJq7Kvzc6qtQuJeFWzNohCK/To5418aTUwDPDwX7RFo2PUpODjdYfb3UGnoykZtPB96aEpLCsmNjWa9hZt9HV65DotAifThsuRcqAxE6U82PDluXA7kLKxDWyL9GpUQH7F+KkInYuZ0grBLWJuGKT2ilhmAhZDauSKFbKLpzjIZxXPpyTAC2K3dMR2ifzmnM0RPvlEP1HX7Dv+lDzAywmSzzY8/mKUM80awD37Xd4Hybw3o/RezfG3qcJdj9ORMw1j2LvzTcc9r/ixcEPPH04Rk7fI8Ji8KfMJj5BF5GtbGPj6IwUjoSSjWMfvVMfndcUszLKHVLbev4ZO5tneDwYYbfjIztV+BNLNqhkBopUTwAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Stack Overflow 2022 Developer Survey Results showing Elixir is number 2 loved language behind Rust and ahead of typescript in fourth&quot;
        title=&quot;&quot;
        src=&quot;/static/223143bfa1947ad9febe25ec4a51de72/fcda8/loved-languages.png&quot;
        srcset=&quot;/static/223143bfa1947ad9febe25ec4a51de72/12f09/loved-languages.png 148w,
/static/223143bfa1947ad9febe25ec4a51de72/e4a3f/loved-languages.png 295w,
/static/223143bfa1947ad9febe25ec4a51de72/fcda8/loved-languages.png 590w,
/static/223143bfa1947ad9febe25ec4a51de72/efc66/loved-languages.png 885w,
/static/223143bfa1947ad9febe25ec4a51de72/c83ae/loved-languages.png 1180w,
/static/223143bfa1947ad9febe25ec4a51de72/06868/loved-languages.png 1974w&quot;
        sizes=&quot;(max-width: 590px) 100vw, 590px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;However it doesn’t even appear in the list of languages used by developers professionally.
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/40189a97588c95cc1fc373a43ab17ac2/f3015/work-languages.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 79.72972972972973%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAABYlAAAWJQFJUiTwAAADCUlEQVQ4y4WUaW8aVxSG/TPS2o4JTgwMYAMDM8zCsMwCDKvZMaZ24sjBsZO2UlXaSv3QSK36qX/56YGmiWq77Yczy5Xuc9/3LHfnWcrjfkTTPhGlxu4Lm2jK5TDtElWqxDMBz499Htvzd+w8WEx77L1wUApdrMENRmuFFdzgXKzp3/1KyuizF7M/Hfz/wKRHxhuhDW9offsHWeccRZuRbl+jdW7l/zVa9Tsionw/XuFAcf8DqPikyl3M2TUFe0CiPCNjz4jneijuOZnCkGR+hub+SK3zG3awIGefbkU8AEZkUdEaONM+z1SPbL5PxpqQqZ2TUAek5X2sTYgXzkjqS8xwjdX4SXJclf3+PaDk7WnMZ/jNlMZ8xLHk70hviqK+WFyQNKakSwLaHOJck6lckTXmBK0PHOVORUz1ccvOtEW+3UBvtsVKm7TeQTUnpCQ21rPWJaniAlUfYFl9itaYdH7KgQCjH1VugfsJl4xRZz7vkRXbuVKDbDUUNV1OJJdpfciJNSdrnlEoDjH0CSfqmLLxlk5lzZ7ifAZG5bF7VKPg+KxWL+X0VzjVlxSlugVzRt4eidpNjMmLomxxJjBZVxe41jva5TVfbtroY2F2opI/1ZnQHi25up2Tq4qdoINebqCWWmjWqeSrL7AJqjZHMy+wa7foziuqpTtG9Z9RiiGxbFNy6f5l+VC6/0DxePvulO4kxKj5FMtNzNpUAEOKRgetMqFgDMkXWuJCLNtL6vU1QfVOvrvEcuFn4EblXsylHIT4zVBaponjXKBJIUzJrW40UQ35tr/CltYxzJBKac5Z/Xfp3c3eyhb2jyofCvSJ5HIZ9pi2rkhJm9hmHV+U5qTa+eIAs3IpwAVGbkxYeS1q5zxNVmRv8HjbRCSeS6wmc96Mx7SrLSwzkLnukyt20UsL6t6K770PWFKYLxIlgfn/Pnob6/uJGolCm17Q4+vRYAvtSsU9Ww7xfuB9/xd895LdRPkB7NHLIbodQ5cn8RoHcgEk5MrqBktyapdEOmRfRi1y4n3qu/vxJ2ucIcIQsLjYAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Stack Overflow 2022 Developer Survey Results showing what languages engineers use professionally and Elixir is not included&quot;
        title=&quot;&quot;
        src=&quot;/static/40189a97588c95cc1fc373a43ab17ac2/fcda8/work-languages.png&quot;
        srcset=&quot;/static/40189a97588c95cc1fc373a43ab17ac2/12f09/work-languages.png 148w,
/static/40189a97588c95cc1fc373a43ab17ac2/e4a3f/work-languages.png 295w,
/static/40189a97588c95cc1fc373a43ab17ac2/fcda8/work-languages.png 590w,
/static/40189a97588c95cc1fc373a43ab17ac2/efc66/work-languages.png 885w,
/static/40189a97588c95cc1fc373a43ab17ac2/c83ae/work-languages.png 1180w,
/static/40189a97588c95cc1fc373a43ab17ac2/f3015/work-languages.png 1804w&quot;
        sizes=&quot;(max-width: 590px) 100vw, 590px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Golang and Rust both appear on the list of languages used by developers professionally and have been around for about as long as Elixir has. Rust and Elixir were both initially created in 2012 and Golang was created in 2009. This makes sense though as we have seen larger organizations like Google, Meta, etc get behind these languages. Golang was developed internally at Google which makes sense why Google has supported it. However, Rust was developed at Mozilla and has been adopted and supported by lots of organizations. You can see Meta talk about it’s &lt;a href=&quot;https://engineering.fb.com/2021/04/29/developer-tools/rust/&quot;&gt;history of using Rust&lt;/a&gt; and in &lt;a href=&quot;https://engineering.fb.com/2022/07/27/developer-tools/programming-languages-endorsed-for-server-side-use-at-meta/&quot;&gt;2022 even going so far as to endorse it for server side use internally&lt;/a&gt;. While there are lots of things to consider when discussing why these languages have been adopted by larger organizations and sponsored, it is mostly just to show languages of similar ages have been adopted professionally at a faster pace.&lt;/p&gt;
&lt;p&gt;That being said, the point of this post is to help others avoid similar mistakes and help the community understand some shortcomings that can be improved for future adopters. Also some of the issues can be easily avoided or have been improved by the open source community already for future adopters. Hopefully over the years Elixir will start to show up in the Stack Overflow Developer Survey as one of the languages both loved and used by professionals.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Calculating Progressive Income Taxes]]></title><description><![CDATA[Progressive Income Taxes In the United States (as well as other locations), we have a progressive income tax system. What this means is that…]]></description><link>https://boredhacking.com/calculating-progressive-income-taxes/</link><guid isPermaLink="false">https://boredhacking.com/calculating-progressive-income-taxes/</guid><pubDate>Wed, 18 Jan 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;Progressive Income Taxes&lt;/h2&gt;
&lt;p&gt;In the United States (as well as other locations), we have a progressive income tax system. What this means is that the percentage or amount you pay in taxes increases as your income increases, basically higher income individuals pay a larger percentage of their income in taxes. The word “progressive” is used to describe this tax system because the tax rate progresses as your income increases. I will not be going into the advantages and disadvantages or alternative tax systems in this post. You can read more about progressive tax systems on &lt;a href=&quot;https://www.investopedia.com/terms/p/progressivetax.asp&quot;&gt;investopedia&lt;/a&gt; if you’re interested.&lt;/p&gt;
&lt;p&gt;Although there are multiple nuances to calculating US federal income taxes we will not be going into detail on every aspect of calculating such taxes. Instead we will focus on the most basic examples and ignore things such as deductions. In the US there are different progressive tax brackets depending if you file as a single filer, married (filed jointly), married (filed separately), or the head of the household. For the purpose of this post we will only look at single filers for simplicity but this will all be applicable to any of the filing scenarios/personas. If we look at the &lt;a href=&quot;https://www.nerdwallet.com/article/taxes/federal-income-tax-brackets&quot;&gt;2023 tax brackets&lt;/a&gt; (taxes due in April 2024) we can see the following brackets for a single filer (courtesy of &lt;a href=&quot;https://www.nerdwallet.com/&quot;&gt;nerdwallet.com&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/a1d880da47e4eba85810e9a84a0b8d2e/016a8/nerd-wallet-single-filer-taxes.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 75%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABYlAAAWJQFJUiTwAAAByUlEQVQ4y32TyY7bMBBE9f8/leQ4OfsyMmAF3mTJWq3Va4evgzI8RjACCiSb3dVVJBXtdjtbLpeWZbl99z0eD8d3+7fbzaKirS2tjnYMYz10ljWlpeXRtvnB8qbyWNWfrJ0GB+v/gZxhnixq2tbiOLY8z22cJvv4/WE/f/2wOKhODweb5tmKsrTP+NOSP0lYTyFvtH4YvqDre5vPZ4vGcbQ2kJ7D4nK52Ol0sqZpbArx6/XqmEKjqgpq69q6sN91nc2hEfmvcMskQ8pHoA+dKCyDqvv97nGKaUojEUPwfob3gAhFJEE8BOlZllmapnYIdrkwOWBOjH2w3+8d5K7XaxeAm2gYRreAOmxTTAOBGM0oQBkxlDIHUi0Ot4xNWWZDthixBqmIGHElMgmAA9sRgaIonpaxJSvb7daLydlsNs+jkHVGXofsw+G3jCougDOQHbpikwsBzLX3Okohaz9DCCUXy6/nI0Iss6ZYeyLEAQ6BEyogy1iQJWz8ewW1LRYLW61WX25XcwTprJ+W9R4hEFBAMvsQoJicd1ALII2wxEKPk2LsoFYPnjFJEn+Lsse5aU4+d+C3LKkilGJ152OfIyDuf0Qofofq/wL8nX5UQO2MeQAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;single filer 2023 tax brackets from nerdwallet&quot;
        title=&quot;&quot;
        src=&quot;/static/a1d880da47e4eba85810e9a84a0b8d2e/fcda8/nerd-wallet-single-filer-taxes.png&quot;
        srcset=&quot;/static/a1d880da47e4eba85810e9a84a0b8d2e/12f09/nerd-wallet-single-filer-taxes.png 148w,
/static/a1d880da47e4eba85810e9a84a0b8d2e/e4a3f/nerd-wallet-single-filer-taxes.png 295w,
/static/a1d880da47e4eba85810e9a84a0b8d2e/fcda8/nerd-wallet-single-filer-taxes.png 590w,
/static/a1d880da47e4eba85810e9a84a0b8d2e/efc66/nerd-wallet-single-filer-taxes.png 885w,
/static/a1d880da47e4eba85810e9a84a0b8d2e/c83ae/nerd-wallet-single-filer-taxes.png 1180w,
/static/a1d880da47e4eba85810e9a84a0b8d2e/016a8/nerd-wallet-single-filer-taxes.png 1576w&quot;
        sizes=&quot;(max-width: 590px) 100vw, 590px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;There are a few important facts to be aware of regarding how progressive tax brackets work. The tax bracket rate you are in based on your income is not applied to all of your income. Your income is divided into taxable chunks. For example if you make $20,000 dollars based on the above tax brackets, the first $11,000 of your income is taxed at 10% and then the next $9,000 of that $20,000 is taxed at 12%. This logic can be applied to any level of income. The percentage of your taxable income that you end up paying in taxes is your effective tax rate (this will be less than the tax rate for your income bracket). This can be determined by dividing your total tax owed by your total taxable income. For example in the above scenario the total taxable income is &lt;code class=&quot;language-text&quot;&gt;($11,000 * 0.10) + ($9,000 * 0.12) = $2,180&lt;/code&gt; and then &lt;code class=&quot;language-text&quot;&gt;$2,180 / $20,000 = 0.109&lt;/code&gt; which is less than 12%. Now that we know the basics of calculating progressive income taxes let’s hop into some code.&lt;/p&gt;
&lt;h2&gt;Programmatically Calculating Progressive Income Taxes&lt;/h2&gt;
&lt;p&gt;While working on a &lt;a href=&quot;https://isocalculator.com/&quot;&gt;small side project to calculate ISO Taxes&lt;/a&gt; I needed to programmatically calculate taxes based on a progressive tax bracket. However I found it rather hard finding a library or an example algorithm to follow online, surely this must be a solved problem? I had multiple different tax brackets I wanted to calculate and I wanted a fairly generic algorithm that could do this based on a set of brackets passed in to avoid duplicate code. However, upon first glance most examples online were a series of if/else statements like &lt;a href=&quot;https://github.com/rsjahnke/progressive-income-tax-calculator/blob/master/progressive_income_tax.php&quot;&gt;this one&lt;/a&gt; and &lt;a href=&quot;https://www.geeksforgeeks.org/income-tax-calculator-using-python/&quot;&gt;this one&lt;/a&gt;. This meant crafting multiple functions that were a series of if/else statements for each set of tax brackets. For example a function like this&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;calculateIncomeTax&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token literal-property property&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;11000&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; amount &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.1&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;44725&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;11000&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.12&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1100&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;95375&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;44725&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.22&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5147&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;182100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;95375&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.24&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;16290&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;231250&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;182100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.32&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3104&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;578125&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;231250&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.35&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;52832&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;578125&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.37&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;174238.25&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can imagine it is rather cumbersome to continuously type out these else if statements and you need to know not only the tax rates and top of brackets but also the amount of tax applied to your income at lower rates.&lt;/p&gt;
&lt;p&gt;The good news is there is a fairly simple algorithm you can use to calculate taxable income based on a set of brackets passed in. Let’s first see what this looks like in pseudocode before looking at actual code.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;input: income amount, brackets which is a list of top of bracket amount and tax rate
output: taxed amount

taxed amount starts at 0
Loop over the brackets passed in
   If the income amount is greater than the top of the tax bracket
       Subtract max bracket amount of the previous bracket from current bracket and multiply that by the current bracket tax rate
       Add that amount to the tax amount value
   Else
       Subtract max bracket amount of the previous bracket from the income amount and multiple by the tax rate
       Add that to the tax amount value

return the total taxed amount&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now let’s take a look at some actual javascript code for this algorithm&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;calculateTaxAmount&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token literal-property property&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; number&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;brackets&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;maxAmount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; number&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; number &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; taxAmount &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; index &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; index &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; brackets&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; index&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; brackets&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;index&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;maxAmount&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      taxAmount &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;brackets&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;index&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;maxAmount &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; brackets&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;index &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;maxAmount&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;
        brackets&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;index&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;rate
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      taxAmount &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; brackets&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;index &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;maxAmount&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; brackets&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;index&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;rate
      &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; taxAmount
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; taxAmount
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;federalTaxAmount&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token literal-property property&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; brackets &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;maxAmount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;maxAmount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10275&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;maxAmount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;41775&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.12&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;maxAmount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;89075&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.22&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;maxAmount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;170050&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.24&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;maxAmount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;215950&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.32&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;maxAmount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;539900&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.35&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;maxAmount&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;Infinity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.37&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calculateTaxAmount&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;amount&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; brackets&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see we have the first tax bracket be an amount of 0 at a rate of 0. This allows us to start our for loop at the first index of the bracket and not run into an index out of range issue. And with that we have a simple algorithm for calculating progressive tax incomes! I’ve also pulled this algorithm into its own npm package for reuse by others called &lt;a href=&quot;https://github.com/jrusso1020/us-taxes&quot;&gt;us-taxes&lt;/a&gt;. For now it exposes the above algorithm which is extensible with your own tax brackets and has a function for calculating federal taxes for the current tax year and previous tax year (2022 and 2023). Hopefully this post can save some others in the future looking to do this themselves. Something that would make this even easier in the future would be a free API for getting tax rates for a given year and filing status, however there doesn’t seem to be such a free API currently. In the us-taxes npm package I had to manually input the tax brackets which makes it difficult to do for large ranges of years or different states.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[The Comeback]]></title><description><![CDATA[Over the last couple of years I haven’t made a concerted effort to blog, and in general this website has been fairly unmaintained. My last…]]></description><link>https://boredhacking.com/the-comeback/</link><guid isPermaLink="false">https://boredhacking.com/the-comeback/</guid><pubDate>Fri, 23 Dec 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Over the last couple of years I haven’t made a concerted effort to blog, and in general this website has been fairly unmaintained. My last post was in July 2021 which was over a year and a half ago, and most of my contributions to this website have been merging dependency updates. I did however author one blog post in the past year on &lt;a href=&quot;https://medium.com/brexeng&quot;&gt;Brex’s Engineering Blog&lt;/a&gt; which you can check it out if you like: &lt;a href=&quot;https://medium.com/brexeng/backstage-adoption-at-brex-b415e0e7d3a6&quot;&gt;Backstage Adoption at Brex&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That being said, this blog post is meant to spark the comeback of my personal blog! This blog itself will not be a long or well thought out post but will function as a warmup for things to come. I’ve found in the past that the best methods to get into the writing mood are to constantly write down blog ideas when they come, and then to sit down and get my thoughts out. So while I have been keeping track of potential ideas, I haven’t spent the time to just sit and write. So I’ve decided to start small with this blog post. One word of wisdom I can give in this post for others who want to start a blog or get back into blogging: write something, anything and post it. The audience may be small or even just yourself, but it can be the spark you need to kickstart your blogging.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Elixir Learnings]]></title><description><![CDATA[Elixir was a deliberate choice when Brex was started, as outlined by our co-founder Pedro in this blog post. There are a few main reasons we…]]></description><link>https://boredhacking.com/elixir-learnings-and-hiring/</link><guid isPermaLink="false">https://boredhacking.com/elixir-learnings-and-hiring/</guid><pubDate>Tue, 20 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Elixir was a deliberate choice when Brex was started, as outlined by our co-founder Pedro in &lt;a href=&quot;https://medium.com/brexeng/why-brex-chose-elixir-fe1a4f313195&quot;&gt;this blog post&lt;/a&gt;. There are a few main reasons we picked Elixir. One is the fact it was built on the Erlang VM, which offers reliability and fault tolerance out of the box. Another is its functional nature, which forces immutability and makes complex code easier to reason about. Others include its great concurrency primitives and macros for extending the language. These are important features for a highly reliable financial infrastructure. As of 2021, a majority of Brex’s business logic has been developed in Elixir, which means all product engineers have had to onboard and learn Elixir. Brex has hired and onboarded over 150 engineers to write Elixir in a production system and has over 70 elixir services running in production, which gives us some unique insights into how to rapidly hire and onboard Elixir engineers. Over the last 3-4 years, we have encountered some issues and learned lessons that might be helpful to other organizations adopting Elixir.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This post was sponsored by digital product consultancy &lt;a href=&quot;https://dockyard.com&quot;&gt;DockYard&lt;/a&gt; to support the Elixir community and to encourage its members to share their stories.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Hiring&lt;/h2&gt;
&lt;p&gt;Brex has more than doubled engineering every year since the beginning of 2019. In January of 2019 there were around 20-30 engineers. By January of 2020, we were at around 70 engineers, and as of January of 2021 we were around 200 engineers. Early on at Brex, we realized it was going to be hard to hire for Elixir experience specifically. Elixir is still a fairly young language, although more and more companies are adopting it. As we needed to hire rapidly, there wasn’t a plethora of Elixir engineers looking for new jobs to fill our open headcount. Therefore, at Brex we’ve adopted a language-agnostic hiring process, focused on hiring engineers who meet our overall technical expectations and align with our company’s values. Elixir knowledge is not a prerequisite to interview at Brex; in fact, very few engineers who end up joining Brex have any Elixir experience. This means almost all engineers who have joined Brex have had to learn Elixir on the job, which requires us to focus on onboarding and documentation around Elixir. Generally speaking, engineers are able to learn Elixir in under a month and be fully onboarded within two months. However, this doesn’t mean all engineers who join Brex have exactly the same experience. Engineers who come from dynamically typed languages (especially Ruby) or functional languages generally have an easier time onboarding and learning Elixir than engineers who come from statically typed languages. The lack of static types makes it hard for engineers with this background to grasp input and outputs of functions in Elixir. Typespecs can be helpful but they aren’t always correct, and without enforcement or a culture around them, a majority of our functions do not have them. Typespecs and dialyzer could help solve this issue, but if they are not adopted early it’s hard to retroactively roll them out across a large codebase without a concerted effort.&lt;/p&gt;
&lt;h2&gt;Macros&lt;/h2&gt;
&lt;p&gt;Over the last few years, we have written a lot of Elixir code (around a million lines of business logic), and in that time we’ve also made some mistakes with Elixir. One of these mistakes was around our use of macros. Macros are useful and have their place; however, if you follow the &lt;a href=&quot;https://hexdocs.pm/elixir/master/library-guidelines.html#avoid-macros&quot;&gt;Elixir library guidelines&lt;/a&gt; it is recommended to avoid macros. Macros can hurt developer productivity due to their difficulty to reason about and debug. Although we have a lot of great macros at Brex that make our lives easier, there’s also a number of them we realize aren’t as useful. Now, some macros are rarely used or even discouraged because they constantly gave engineers issues, they were hard for product engineers to debug, or they didn’t provide enough value compared to another way of accomplishing the same thing. New engineers unfamiliar with Elixir found macros especially hard to reason about and read, including both DSLs and &lt;code class=&quot;language-text&quot;&gt;__using__&lt;/code&gt; macros. Unlike the rest of Elixir, which is generally very legible, macros can be quite nuanced and obtuse if you are unfamiliar with them.&lt;/p&gt;
&lt;p&gt;However, as I mentioned, there are a lot of good use cases for macros. An engineer at Brex, Lizzie Paquette, actually gave a great talk at Code Beam SF 20 about some of our internal macros which you can checkout on &lt;a href=&quot;https://www.youtube.com/watch?v=55-X7rSw8M0&quot;&gt;YouTube&lt;/a&gt;. We have many &lt;code class=&quot;language-text&quot;&gt;__using__&lt;/code&gt; macros from internal libraries that allow engineers to easily and quickly implement complex abstractions. One such example is a library that allows engineers to easily define publishers and consumers of events which interact with our asynchronous events infrastructure (utilizing Kafka under the hood). Macros also allow us to create DSLs and extend the Elixir language so Engineers can focus on business problems. Examples of helpful DSL macros our engineers use internally include a simplified DSL for defining Elixir structs with type annotations similar to Ecto schemas, a DSL for defining Ecto.Schema changeset validations, and a DSL for defining enums. While I definitely agree macros should be used sparingly, these are some of the successful use cases we’ve seen internally.&lt;/p&gt;
&lt;h2&gt;Reducing Boilerplate and Enforcing Standards&lt;/h2&gt;
&lt;p&gt;When we initially started using Elixir, it was a fairly young language with a small but strong community. However, this also meant we didn’t find a lot of external libraries that fit our needs. Therefore, we decided to start writing internal libraries for certain use cases. The main two reasons for writing internal libraries were to reduce boilerplate and enforce standards. Some examples of reducing boilerplate were the macros mentioned in the previous section and the &lt;code class=&quot;language-text&quot;&gt;__using__&lt;/code&gt; macros that are common in our libraries. &lt;code class=&quot;language-text&quot;&gt;__using__&lt;/code&gt; macros allow us to abstract away a large amount of functionality so developers only need to write their own business logic. The DSLs we provide also allow engineers to simplify common use cases like Elixir structs and enums. Furthermore, we wanted to enforce standards through our libraries. An example of this is our wrapper around Ecto.Schema, which makes field values required and immutable by default but also allows for escape hatches where needed via schema field annotations. At this time, we have over 40 internal libraries that allow engineers to move quicker.&lt;/p&gt;
&lt;p&gt;Nevertheless, there are drawbacks to having so many internal libraries. The largest issue we found with them is they were hard for new engineers to learn. It was common for new engineers to be unsure of where a Brex namespaced module came from or what it did. However, a benefit of using Elixir is its great tooling, including documentation. We took advantage of Elixir’s Hexdocs to auto generate and internally host our libraries’ documentation. But these docs were not discoverable on their own. So, in order to better teach new engineers about our internal libraries and give them the tools to learn themselves, we created an onboarding session around our internal libraries and some of the major ones they will use on a day to day basis. We also supplemented our Hexdocs documentation with some resources that live alongside the rest of our engineering documentation. Our internal libraries are incredibly helpful, but come with the need to properly document and educate new engineers on their use.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Elixir is a great language and the work the Elixir Core team has put into the tooling and core libraries is amazing. However, since Brex was an early adopter of Elixir and a hyper-growth startup, we encountered a number of speed bumps very quickly that we had to solve to continue scaling. Finding great Elixir developers quickly is still a fairly hard challenge, but there are plenty of great developers that can quickly learn the language, especially if they come from dynamic and functional language backgrounds. Using macros is a nuanced art, but when used well they can accelerate development for your organization. Hopefully these lessons can help other organizations both adopt and rapidly scale their Elixir usage without hitting some of our speed bumps.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Thank you to Lars Wikman and Susan Watkins for reading and editing drafts of this blog post&lt;/em&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[One Year of Elixir: How it compares to Ruby]]></title><description><![CDATA[Last year I started a new job at Brex where Elixir is the primary programming language for business logic. This was my first real adventure…]]></description><link>https://boredhacking.com/one-year-of-elixir/</link><guid isPermaLink="false">https://boredhacking.com/one-year-of-elixir/</guid><pubDate>Sun, 21 Feb 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Last year I started a new job at &lt;a href=&quot;https://brex.com&quot;&gt;Brex&lt;/a&gt; where Elixir is the primary programming language for business logic. This was my first real adventure into Elixir after working in Ruby (mostly) for my professional career. Since José Valim came from the Ruby world, Elixir was a common buzzword I heard for years. I had done a tutorial or two here and there but never gotten to really use it. Now, looking back at the past year I’ve become fairly comfortable with Elixir, and wanted to outline some of the things I really enjoy about Elixir and some of the things I miss from Ruby.&lt;/p&gt;
&lt;h2&gt;The Good Parts of Elixir&lt;/h2&gt;
&lt;p&gt;First off there are lots of great things about the Elixir programming language. This post by no means is going to cover all them or talk about when you should use Elixir vs Ruby. These are solely a few of my opinions and observations I’ve gathered over the past year on Elixir coming from a Ruby (on Rails) background.&lt;/p&gt;
&lt;h3&gt;Processes and Concurrency (No Global Interpreter lock)&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://elixir-lang.org/getting-started/processes.html&quot;&gt;Processes&lt;/a&gt; are an abstraction built into the language (thanks erlang), that are extremely lightweight in terms of memory and CPU and allow code to run in isolation and concurrently. Processes provide the building blocks for concurrency in Elixir and allow us to write distributed and fault tolerant code. Because of processes writing concurrent code in Elixir is incredibly simple and straightforward. However in Ruby, there is the concept of the Global Interpreter Lock (GIL) which prevents multiple Ruby threads from executing at the same time.&lt;/p&gt;
&lt;h3&gt;Great Documentation&lt;/h3&gt;
&lt;p&gt;Elixir does a really good job when it comes to documentation. Via hexdocs, developers can easily write documentation inline with their code and then generate and host it for free! This makes it incredibly low effort to create documentation for your OSS. The Elixir language and other libraries developed by the core team take full advantage of hexdocs, creating very robust documentation. Hexdocs are very well designed which makes them incredibly easy to read and navigate as well. You can even write and run tests from documentation which is a great way to write multi-purpose code examples in your documentation. Just take a look at the &lt;a href=&quot;https://hexdocs.pm/elixir/DateTime.html#content&quot;&gt;Elixir DateTime docs&lt;/a&gt;, the below &lt;code class=&quot;language-text&quot;&gt;@doc&lt;/code&gt; module attribute will generate the hexdocs and the examples will be run during tests just by adding &lt;code class=&quot;language-text&quot;&gt;doctest DateTime&lt;/code&gt; to the xxx_test.exs file.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;elixir&quot;&gt;&lt;pre class=&quot;language-elixir&quot;&gt;&lt;code class=&quot;language-elixir&quot;&gt;&lt;span class=&quot;token doc&quot;&gt;&lt;span class=&quot;token attribute&quot;&gt;@doc&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&quot;
Compares two datetime structs.
Returns `:gt` if the first datetime is later than the second
and `:lt` for vice versa. If the two datetimes are equal
`:eq` is returned.
Note that both UTC and Standard offsets will be taken into
account when comparison is done.
## Examples
    iex&gt; dt1 = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: &quot;AMT&quot;,
    ...&gt;                 hour: 23, minute: 0, second: 7, microsecond: {0, 0},
    ...&gt;                 utc_offset: -14400, std_offset: 0, time_zone: &quot;America/Manaus&quot;}
    iex&gt; dt2 = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: &quot;CET&quot;,
    ...&gt;                 hour: 23, minute: 0, second: 7, microsecond: {0, 0},
    ...&gt;                 utc_offset: 3600, std_offset: 0, time_zone: &quot;Europe/Warsaw&quot;}
    iex&gt; DateTime.compare(dt1, dt2)
    :gt
&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token attribute variable&quot;&gt;@doc&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;since:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;1.4.0&quot;&lt;/span&gt;
&lt;span class=&quot;token attribute variable&quot;&gt;@spec&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;compare&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token module class-name&quot;&gt;Calendar&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token module class-name&quot;&gt;Calendar&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;token atom symbol&quot;&gt;:lt&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token atom symbol&quot;&gt;:eq&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token atom symbol&quot;&gt;:gt&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;compare&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Pattern Matching&lt;/h3&gt;
&lt;p&gt;When I was in college I took a functional programming course which taught me &lt;a href=&quot;https://ocaml.org/&quot;&gt;OCaml&lt;/a&gt;. This was my first foray into functional programming and way back then I realized how incredibly powerful and useful pattern matching was. No more complex and hard to read switch/if statements. So when I first started writing Elixir, I was excited to get to use &lt;a href=&quot;https://elixir-lang.org/getting-started/pattern-matching.html&quot;&gt;pattern matching&lt;/a&gt; again. For example, the &lt;code class=&quot;language-text&quot;&gt;=&lt;/code&gt; sign is the match operator in Elixir not assignment. Pattern matching allows us to match simple values, data structures, and even functions. So what does this look like in practice?&lt;/p&gt;
&lt;p&gt;Here we can see how we can extract values of a tuple into variables. We also see an example of the pin operator &lt;code class=&quot;language-text&quot;&gt;^&lt;/code&gt; which will match the current value vs extracting it into a variable. This makes writing assertive code straightforward.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;elixir&quot;&gt;&lt;pre class=&quot;language-elixir&quot;&gt;&lt;code class=&quot;language-elixir&quot;&gt;iex&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; c&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token atom symbol&quot;&gt;:hello&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;world&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token atom symbol&quot;&gt;:hello&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;world&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
iex&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; a
&lt;span class=&quot;token atom symbol&quot;&gt;:hello&lt;/span&gt;
iex&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; b
&lt;span class=&quot;token string&quot;&gt;&quot;world&quot;&lt;/span&gt;
iex&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;^&lt;/span&gt;c &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;34&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token module class-name&quot;&gt;MatchError&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; no match of right hand side &lt;span class=&quot;token attr-name&quot;&gt;value:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;34&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Another example of the power of pattern matching is to dynamically dispatch functions based on the parameters. For example the below shows the &lt;code class=&quot;language-text&quot;&gt;first&lt;/code&gt; function defined to handle three different parameter patterns and dynamically choose the correct function definition.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;elixir&quot;&gt;&lt;pre class=&quot;language-elixir&quot;&gt;&lt;code class=&quot;language-elixir&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;do:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;nil&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; _y&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;do:&lt;/span&gt; x
&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;x &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; _rest&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;do:&lt;/span&gt; x&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And lastly it can be great for control flows via &lt;code class=&quot;language-text&quot;&gt;case&lt;/code&gt; statements or &lt;code class=&quot;language-text&quot;&gt;with&lt;/code&gt; statements like the below, which will only continue along the current flow if the previous pattern matches. For example, &lt;code class=&quot;language-text&quot;&gt;coordinate&lt;/code&gt; must be a three-tuple, and each &lt;code class=&quot;language-text&quot;&gt;evaluate&lt;/code&gt; function must return an ok tuple to do the final addition. If any pattern doesn’t match it will go to the &lt;code class=&quot;language-text&quot;&gt;else&lt;/code&gt; clause and attempt to pattern match there to return 0 (There is a scenario where no pattern matches though and we get a &lt;code class=&quot;language-text&quot;&gt;MatchError&lt;/code&gt;)&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;elixir&quot;&gt;&lt;pre class=&quot;language-elixir&quot;&gt;&lt;code class=&quot;language-elixir&quot;&gt;with &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; z&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;-&lt;/span&gt; coordinate&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token atom symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; x_val&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;evaluate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token atom symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y_val&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;evaluate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;y&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token atom symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; z_val&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;evaluate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;z&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
  x_val &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; y_val &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; z_val
&lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;
  &lt;span class=&quot;token boolean&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token atom symbol&quot;&gt;:error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; _reason&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Standard Library and Built in Tooling&lt;/h3&gt;
&lt;p&gt;The Elixir standard library comes with a number of useful functions and modules, as well as first class tooling. First off Exunit and async tests are a big win over Ruby. When working in Ruby, the first thing was to pull in RSpec and any necessary matchers, but in Elixir this isn’t necessary because exunit is built into the language. You have a test framework out of the box, and it allows you to run tests asynchronously as well! This was a huge pain point back when I was in a Ruby on Rails monolith, running all the tests synchronously just got slower and slower over time but in Elixir even in a large service it’s relatively fast with async tests runs. Another great built in tool in Elixir is &lt;a href=&quot;https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html&quot;&gt;Mix&lt;/a&gt; which is “a build tool that ships with Elixir and provides tasks for creating, compiling, testing your application, managing its dependencies and much more.” Mix allows you to quickly and easily 1) start new Elixir projects via &lt;code class=&quot;language-text&quot;&gt;mix new&lt;/code&gt;, 2) manage your dependencies and retrieve them via &lt;code class=&quot;language-text&quot;&gt;mix deps.get&lt;/code&gt;, 3) run tests via &lt;code class=&quot;language-text&quot;&gt;mix test&lt;/code&gt;, and 4) format your code to make it easy to read and digest via &lt;code class=&quot;language-text&quot;&gt;mix format&lt;/code&gt;. In Ruby this would be replaced by about 4 separate tools: &lt;code class=&quot;language-text&quot;&gt;rails new&lt;/code&gt; or templates for starting new projects, 2) bundler for managing and retrieving dependencies, 3) RSpec for running tests, and 4) Rubocop or another third party tool for formatting and checking your code. This makes it incredibly straightforward and easy to get a project up and running with ease.&lt;/p&gt;
&lt;h3&gt;Pipes&lt;/h3&gt;
&lt;p&gt;Pipes (&lt;code class=&quot;language-text&quot;&gt;|&gt;&lt;/code&gt;) are a great way to easily chain function calls together in Elixir, similar to how you would chain function calls in Ruby. Before I knew becoming acquainted with Elixir, pipe operators were a bit confusing, but after a quick introduction you can easily spot them and understand the flow of code.&lt;/p&gt;
&lt;p&gt;In Ruby, function chains may look something like&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre class=&quot;language-ruby&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;text&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
  downcase&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
  replace_non_words_with_spaces&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
  drop_extra_whitespace&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
  join_with_dashes&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;but in Elixir we can use pipes to accomplish this like so&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;elixir&quot;&gt;&lt;pre class=&quot;language-elixir&quot;&gt;&lt;code class=&quot;language-elixir&quot;&gt;title
&lt;span class=&quot;token operator&quot;&gt;|&gt;&lt;/span&gt; &lt;span class=&quot;token module class-name&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;downcase
&lt;span class=&quot;token operator&quot;&gt;|&gt;&lt;/span&gt; &lt;span class=&quot;token module class-name&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token regex&quot;&gt;~r/\W/&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;|&gt;&lt;/span&gt; &lt;span class=&quot;token module class-name&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split
&lt;span class=&quot;token operator&quot;&gt;|&gt;&lt;/span&gt; &lt;span class=&quot;token module class-name&quot;&gt;Enum&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;-&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;The Things I Miss From Ruby&lt;/h2&gt;
&lt;p&gt;That being said, there are still a lot of good things about Ruby and some things I miss. These are probably the biggest two things I’ve really missed over the past year.&lt;/p&gt;
&lt;h3&gt;The Community and Resources&lt;/h3&gt;
&lt;p&gt;Personally, the greatest thing about Ruby is the massive community and resources around it. Ruby started in 1995 whereas Elixir is a lot newer, being initially released in 2011. Ruby and Ruby on Rails have gained massive user bases and because of this have a huge number of resources. One of the best things about Ruby is the fact that there will almost always be a library(gem) for what you want to do and they generally are well maintained. On top of that there’s a plethora of tutorials and resources to learn Ruby. A big pain point with Elixir is the smaller community and lack of open source libraries. Although there are a lot of learning resources for new Elixir developers. There’s also a lot of great libraries built by the core Elixir team for most needs, but there’s still not a lot of libraries in comparison to other languages. At Brex, we have needed to write a number of internal Elixir libraries for our specific needs or for third party services which don’t have an SDK in Elixir. A couple of other issues are that a lot of Elixir libraries aren’t well maintained and go dormant often or are maintained by a single maintainer which makes it hard to get updates in a timely manner. That being said Elixir is still a fairly young language and with its continued growth hopefully it will improve.&lt;/p&gt;
&lt;h3&gt;Monkey Patching&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Edit: Since initially publishing this article I have gotten helpful comments/emails about how you can implement monkey patching in Elixir. It involves copying the given library’s full module into your codebase and changing the necessary code to fit your needs. This will override the libraries implementation with your custom code. Although I was familiar with hot code reloading in Elixir this did not come to mind as Monkey Patching. Also I think the main reason I have not seen this in Elixir is because it is an antipattern that should be avoided. For what it is worth, I think what I truly miss is Ruby’s ability to easily override a library’s singular function with ease but in Elixir this would require redefining the whole module and changing bits and pieces. I will leave the original paragraph below though for posterity.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Monkey patching is a way to extend or change a Ruby class, including within libraries, dynamically by writing code directly into your project. This makes it incredibly easy to personalize or customize library functionality for your personal needs or patch a bug as a stop gap until the underlying library can be fixed. In Elixir you can wrap open source libraries with your own code to extend or personalize it but this can be a lot of boilerplate and extra code to just add a simple change. More often than not this may also involve writing a macro which &lt;a href=&quot;https://hexdocs.pm/elixir/master/library-guidelines.html#avoid-macros&quot;&gt;should generally be avoided whenever possible&lt;/a&gt;. However, this doesn’t allow you to fix bugs in an underlying library like monkey patching does. You would need to fork a library and make the change yourself then point your project to your branch in order to do this without waiting for the underlying library to be fixed.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Commenting Code: School vs Industry]]></title><description><![CDATA[Commenting Code in School In school, professors and teaching assistants constantly talked about the need to write comments in your code in…]]></description><link>https://boredhacking.com/commenting-code-school-vs-world/</link><guid isPermaLink="false">https://boredhacking.com/commenting-code-school-vs-world/</guid><pubDate>Sat, 26 Dec 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;Commenting Code in School&lt;/h2&gt;
&lt;p&gt;In school, professors and teaching assistants constantly talked about the need to write comments in your code in order for other people to properly read and understand what you had done. Although you want to ensure others can read your code, in practice commenting your code is not always the best or most necessary way to ensure readability. Thinking back on school, comments were most likely meant as a way to ensure TAs could understand what you were trying to do while reading your code. When you are first learning to program it’s definitely necessary to add a little context to outside readers. However, the larger reason for commenting code in classes was to learn how to properly write technical documentation. As a software engineer you need to be able to properly write technical documentation, and you can initially develop this skill by writing comments in your code. Later in this post, I will try to separate out commenting your code and writing documentation since in practice they are a bit different.&lt;/p&gt;
&lt;h2&gt;Code Commenting in Industry&lt;/h2&gt;
&lt;p&gt;A junior engineer might quickly notice the lack of comments in a real codebase. In a production codebase engineers should strive to break up and write their code in a readable and digestible way. This in turn leads to less inline comments being needed. Code reviews, linting tools, and formatting tools can help ensure readable and digestible code by automatically looking for code smells(a sign of a deeper problem) and readability issues in your code. Properly naming your functions and variables can go a long way instead of using comments. Clearly written code can help cut down on unnecessary comments. However, this doesn’t mean that comments don’t exist in industry codebases.&lt;/p&gt;
&lt;h3&gt;Comments for Complexity or Edge Cases&lt;/h3&gt;
&lt;p&gt;I’ve seen three main reasons for commenting code in professional codebases. The first normally occurs around a particularly complex bit of code, sometimes written to handle edge cases. Generally speaking, software engineers generally write straightforward code, similar to other code paths. However, every once in a while, someone has to solve a particular nuanced business case, handle a weird edge case, or use a rarely used piece of a programming language/framework/library. It might be necessary to write comments in your code to let future users know what you are doing and why. One example from my recent work, I had to write some complex date and datetime manipulation logic for scheduling. This was a little more complex than the day to day work of CRUD operations, so it made sense to write comments about what the code was doing and why. It also had a lot of edge cases that required proper code documentation as well. This allows future code readers to know why the code has added complexity and what it is trying to accomplish. Below is an example of a nuanced business function. The TLDR is that the function takes a date and a day of the week, the date can be the same day of the week or an earlier date. If it’s an earlier date we want to push it forward to the right day of the week (in practice this is explained in the functions documentation).&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;elixir&quot;&gt;&lt;pre class=&quot;language-elixir&quot;&gt;&lt;code class=&quot;language-elixir&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;push_forward_to_correct_day&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;token module class-name&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; date&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; day_of_week&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;# gets the numerical day of week expected to send on value [1,7](mon-sun)&lt;/span&gt;
  numerical_day_scheduled &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token module class-name&quot;&gt;Timex&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;day_to_num&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;day_of_week&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token module class-name&quot;&gt;Timex&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;weekday&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;date&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;# the previous date was pushed back to a date in the same week, let&apos;s shift to the same day of the week&lt;/span&gt;
    date_day_of_week &lt;span class=&quot;token keyword&quot;&gt;when&lt;/span&gt; date_day_of_week &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; numerical_day_scheduled &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt;
      &lt;span class=&quot;token module class-name&quot;&gt;Timex&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;shift&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;date&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;days:&lt;/span&gt; numerical_day_scheduled &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; date_day_of_week&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;# the previous date was pushed back to the previous week, let&apos;s push it forward to the correct day of the week&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;# we do this by pushing it forward to the correct week, then subtracting days&lt;/span&gt;
    date_day_of_week &lt;span class=&quot;token keyword&quot;&gt;when&lt;/span&gt; date_day_of_week &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; numerical_day_scheduled &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt;
      &lt;span class=&quot;token module class-name&quot;&gt;Timex&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;shift&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;date&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;weeks:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;days:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;date_day_of_week &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; numerical_day_scheduled&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;# the previous date was on the correct day of the week, do nothing&lt;/span&gt;
    date_day_of_week &lt;span class=&quot;token keyword&quot;&gt;when&lt;/span&gt; date_day_of_week &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; numerical_day_scheduled &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt;
      date
  &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Comments for TODOs&lt;/h3&gt;
&lt;p&gt;Another reason for commenting code is leaving TODOs or other notes for things that weren’t handled yet but should be. This isn’t something I necessarily agree with, and think engineers should strive to limit as much as possible. TODOs in general should be seen as technical debt since you are aware of something more that you could do to improve your codebase. TODOs are a good way to callout things that need to be done, but more often than not, they will not be handled in a timely manner and if they could be handled with a little more time you should do your best to handle it. Nevertheless, if you are in the process of developing or refactoring, it is okay to leave yourself TODOs to remember to come back to them. Startups need to move fast and therefore acquire a lot of TODOs and other tech debt, so they are common in such an environment.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;elixir&quot;&gt;&lt;pre class=&quot;language-elixir&quot;&gt;&lt;code class=&quot;language-elixir&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# TODO: Make this function handle other currencies besides USD&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;add_balances&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;usd_balance_amount&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; usd_balance_amount&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
  usd_balance &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; usd_balance
&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Documenting your code inline&lt;/h3&gt;
&lt;p&gt;The third main reason I’ve seen in practice for commenting code is to document your code inline. Documentation in general is a whole other topic we’ll discuss next, but inline documentation is a good practice to have. This doesn’t mean commenting every line of your code, but is generally used as a way to document your functions/methods(functionality as well as parameters and return values) and modules/classes. Some languages have ways to generate documentation from inline documentation, and if you are using one of these languages take advantage of it and write documentation! Elixir is a language that is great for this because you can write method documentation and module documentation that you can auto generate and even deploy and host publicly for free. This provides a great developer experience for open source projects and can even be used to host internal documentation. Elixir even goes a step further and allows you to define and run tests for functions in your documentation, which documents your functionality with examples and adds tests. Check out an &lt;a href=&quot;https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/calendar/date.ex&quot;&gt;example in the Elixir codebase&lt;/a&gt; to see what good inline documentation looks like.&lt;/p&gt;
&lt;h2&gt;Code Documentation&lt;/h2&gt;
&lt;p&gt;Although classes focused a lot on code comments, in practice technical writing in software and CS classes really tried to get at the need for proper technical writing and documentation skills. Anything from code comments to technical design docs can be seen as documentation. Commenting your code is the first step to documenting your work, but at companies it’s important to go a step further to ensure that you have well documented code for any new engineer to learn and understand your system or codebase. Instead of focusing so much on commenting your code in line, I think it’s more valuable to write up technical documentation. A lot of the time technical design documents which are written prior to writing code and used to outline the high level approach and tradeoffs of a project or system, can be used for future developers to gain context. However, in practice systems can change from the initial design doc. Therefore it’s also important to write up documentation after finishing a project. Documentation can allow you to outline both at a high level how your code or system works, as well as go into more detail and give examples(code snippets) of how others can interact and extend your code for the future. So although it is valuable and important to learn how to write in line comments, I think it’s more important to focus on high level documentation of your code and being able to write clear, readable code. Inline auto documentation can be a part of this, but sometimes this isn’t enough or high level enough to see how multiple interweaving parts interact. So instead of writing comments throughout your code, document your code!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Onboarding is not a One Way Street]]></title><description><![CDATA[Onboarding can be a very hectic and stressful time when you are starting a new job. New coworkers to meet, new codebases to learn, new…]]></description><link>https://boredhacking.com/onboarding-is-not-a-one-way-street/</link><guid isPermaLink="false">https://boredhacking.com/onboarding-is-not-a-one-way-street/</guid><pubDate>Sun, 08 Nov 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Onboarding can be a very hectic and stressful time when you are starting a new job. New coworkers to meet, new codebases to learn, new languages to learn, new technologies, new processes, and the list can go on and on. Good onboarding materials and processes can go a long way when you’re first starting out. However, it shouldn’t just be a one way street. Onboarding should be a collaborative and incremental process that every new hire(and employee) actively contributes to. Things change from onboarding class to onboarding class, especially in a fast moving startup. It is therefore not only up to the existing members but also the new hires to contribute to the onboarding experience and documentation to keep it up to date and make it better overtime. Here are some recommendations for making onboarding not only productive for you but also better for future new hires.&lt;/p&gt;
&lt;h2&gt;Take Your Time to Onboard&lt;/h2&gt;
&lt;p&gt;Onboarding isn’t a race to the finish line. It can feel like you need to onboard as quickly as possible and be productive right away. However, you have to remember that Rome wasn’t built in a day and this time is important to build a good foundation for the rest of your time at the company. You don’t want to jump in before you’re ready and struggle to keep up. Take your time to properly onboard, and learn as much as you can during this time. Your team will be understanding that you are onboarding and shouldn’t feel like you need to be productive from day 1. Although there is generally a set time period for new hires to still be onboarding, the first month or two generally depending on your company. Take full advantage of your expected onboarding period. When you run into something you don’t know or haven’t seen before, take the time to really dig into it and learn it. Do your own research or ask teammates about it and make sure you fully understand it. Once again, this will pay off in the future and help you compound your knowledge as you continue to learn and work at the company.&lt;/p&gt;
&lt;h2&gt;Write and Update Documentation&lt;/h2&gt;
&lt;p&gt;As you are onboarding hopefully there is already some documentation on how to at the very least setup local development. Depending on your company, you may also have documentation on team specific information, common tasks, etc. Find out what your company uses to store documentation(Google Drive, Github, Notion, Confluence, Dropbox Paper, etc.) and look through it for even more documents. As you go through this documentation, if there’s anything that doesn’t make sense or is outdated make sure to update the documentation. And if you realize there isn’t any documentation for something you encountered then you should write it! Anything you do while onboarding that didn’t have clear directions or documentation, feel free to write it up yourself. Even once you are done onboarding, you should continue this. Every little improvement will benefit someone else down the road and make them productive quicker, multiplying your effect and increasing overall productivity.&lt;/p&gt;
&lt;h2&gt;Take Notes During Onboarding&lt;/h2&gt;
&lt;p&gt;Take notes of things that went well during your onboarding and things that could have gone better. These will be important for improving the situation for the next hire(s). Take these notes to your manager and talk through the good and bad. This will help the organization understand what they are doing well and what they can do to make it better for the next hire on your team. Your manager will want to make sure they are doing everything they can to help you onboard better and improve the situation for the future.&lt;/p&gt;
&lt;h2&gt;Ask Questions&lt;/h2&gt;
&lt;p&gt;Asking questions and getting good answers is incredibly important during onboarding. You may get blocked often while onboarding because there are a lot of unknowns and that’s okay. But don’t wait too long to unblock yourself. One big thing to remember is, you should never hesitate to reach out to someone because they seem too busy. They may be busy but they will normally make the time to help onboard new people. Although not all onboarding buddies may be okay with constant interruptions, it is reasonable that you should try and limit their context shifting. Therefore, setup time to talk with your onboarding buddy or teammate. Setting up time can help limit this but also ensure you get your questions answered. At first this should probably be a set time daily for the first week, but as you continue to onboard it can be less often.&lt;/p&gt;
&lt;h2&gt;Good Onboarding and Helping Out New Hires is a 10X Situation&lt;/h2&gt;
&lt;p&gt;The 10x engineer is often talked about in tech and seen as a unicorn of sorts. For those not familiar, it was commonly thought that a 10x engineer performed 10 times as efficiently as other engineers, performing the work of 10 engineers. However, I don’t think that a 10x engineer should only be more efficient but I think 10x engineers are engineers who help 10X the learning of other engineers as well. A 10x engineer helps their whole team be more efficient by teaching and mentoring them. This applies directly to onboarding and new hires. The faster new hires onboard the faster they can be productive. Spreading information to more people makes everyone better and creates a cycle of spreading information, which can lead not only to a 10x situation but a 100x situation where multiple people within your org are increasing their knowledge and productivity by 10x. The real “unicorn” engineers are the ones who lift up the whole organization or team, and onboarding is a key component of that. Everyone should realize the importance of a good onboarding period for new hires and how it can help the organization as a whole.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Starting a new Elixir Project]]></title><description><![CDATA[I recently started coding in Elixir professionally. It’s relatively easy to develop and add new features at work where most things are set…]]></description><link>https://boredhacking.com/starting-a-new-elixir-project/</link><guid isPermaLink="false">https://boredhacking.com/starting-a-new-elixir-project/</guid><pubDate>Sun, 21 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I recently started coding in &lt;a href=&quot;https://elixir-lang.org/&quot;&gt;Elixir&lt;/a&gt; professionally. It’s relatively easy to develop and add new features at work where most things are set up and running. However, I wanted to get a better understanding of setting up an Elixir project and tooling from scratch. So I decided to start simple and try to write an Elixir wrapper for a 3rd party API. Here are my thoughts and learnings from starting a new Elixir API Wrapper from scratch.&lt;/p&gt;
&lt;h3&gt;Bootstrapping the Project&lt;/h3&gt;
&lt;p&gt;The first thing in any new software project is bootstrapping the project and it’s directory structure. Elixir makes this incredibly easy for libraries using mix. You can get up and running with a library by just calling &lt;code class=&quot;language-text&quot;&gt;mix new name_of_project&lt;/code&gt; and then mix will scaffold out the entire library and get you up and running with a new mix project including a test framework. You can also use mix to scaffold other Elixir based applications using a supervision tree or to start a Phoenix based web app. For the base &lt;code class=&quot;language-text&quot;&gt;mix new&lt;/code&gt; documentation you can take a look &lt;a href=&quot;https://hexdocs.pm/mix/Mix.Tasks.New.html&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Finding an HTTP Client Library&lt;/h3&gt;
&lt;p&gt;The first step in my Client wrapper SDK journey was finding a good Elixir HTTP client which wasn’t as straightforward as I would have liked. Elixir being a relatively new and small community is still changing a lot and often packages are deprecated or abandoned. Although I was able to quickly come across several to choose from the three main one’s I came across were &lt;a href=&quot;https://github.com/myfreeweb/httpotion&quot;&gt;HTTPotion&lt;/a&gt;, &lt;a href=&quot;https://github.com/edgurgel/httpoison&quot;&gt;HTTPoison&lt;/a&gt;, and &lt;a href=&quot;https://github.com/teamon/tesla&quot;&gt;Tesla&lt;/a&gt;. HTTPotion seemed like an early popular package in Elixir but has since been soft-deprecated and redirected users towards Tesla. HTTPoison I have used a couple of times for making simple HTTP requests and seems to have the largest following but also seemed rather restrictive and opinionated. I have come across quite a few other libraries using HTTPoison but after using it a little I was hoping for something else. The last package, Tesla, is based off of Faraday(a ruby HTTP client gem I have used) which was a big plus to me because I am familiar with Faraday and really enjoy it’s composability. Tesla follows suit and allows for easily changing HTTP library backends, JSON parsers, and even defining your own middleware and using predefined composable middleware. These were all big wins for me and led me to my decision to use Tesla as my HTTP client. More recently I have also ran across &lt;a href=&quot;https://github.com/elixir-mint/mint&quot;&gt;Mint&lt;/a&gt; which is developed and maintained by some Elixir core contributors which is a promising sign and something I will need to look into more in the future. I chose to build out my own internal &lt;code class=&quot;language-text&quot;&gt;Client&lt;/code&gt; module and API in my package which would allow me to change out the underlying HTTP client in the future if need be. This is something I would recommend in any language for any HTTP wrapper, that way if need be you can easily switch out the underlying HTTP client with minimal changes to the rest of the application. The full implementation of the client is visible &lt;a href=&quot;https://github.com/jrusso1020/alpaca_elixir/blob/master/lib/alpaca/client.ex&quot;&gt;here&lt;/a&gt; and the &lt;a href=&quot;https://hexdocs.pm/alpaca_elixir/Alpaca.Client.html#content&quot;&gt;documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Testing and Mocking&lt;/h3&gt;
&lt;p&gt;I think there are some things Elixir does really well with testing and some things that could be better. Let’s start with the good though. The first great thing is that mix projects come with Elixir’s builtin testing framework called &lt;a href=&quot;https://hexdocs.pm/ex_unit/ExUnit.html&quot;&gt;ExUnit&lt;/a&gt; that has the bare essentials for testing out of the box. No picking between dozens of open source projects or figuring out the testing framework for your needs. It’s built into all mix projects, maintained by the core Elixir team, and dead simple to get setup and running. For anyone coming from Ruby, it’s fairly similar to RSpec (at least the DSL). And another great benefit of ExUnit is that it comes with async test running. Which can really speed up your testing by running tests in parallel. The only negative to this is making sure that you write your tests to operate in parallel. For the most part you probably won’t encounter any parallel process problems, but for more advanced tests and testing setups this can occur.&lt;/p&gt;
&lt;p&gt;Now the not so good, mocking (especially third party API calls). Mocking in Elixir takes a relatively opinionated approach which you can read about from the Elixir creator, José Valim, &lt;a href=&quot;http://blog.plataformatec.com.br/2015/10/mocks-and-explicit-contracts/&quot;&gt;here&lt;/a&gt;. The gist is that you should try and avoid mocking whenever possible, but when it’s not possible then you should create a test/mock module to replace the module you are interacting with(not the one you are testing) so that you can define its behaviour but keep the contract of functionality. Without debating this article or thought here, I think a general statement is that this has led to lack of simple mocking libraries or approaches in Elixir unless you roll your own. Something I generally try to do is mock external API calls for simple, quick, and reproducible tests. In Ruby there’s the VCR project that allows you to record external API calls and replay them for future tests. This allows you to, after the first attempt, not have to rely on the external API and gives other developers the same responses without having to know your credentials. However, a problem with this approach is that it’s hard to catch changes in the API’s functionality/behavior but let’s look past this for this article. Luckily there’s a similar project in Elixir called &lt;a href=&quot;https://github.com/parroty/exvcr&quot;&gt;ExVCR&lt;/a&gt; that allows you to record HTTP requests and responses. This was great for stubbing my responses to the external API, however there’s a known issue with this library’s speed. Even after recording the request and replaying them it can take seconds per test, whereas it should be almost instant to load in the recorded response and replay it. This is a known &lt;a href=&quot;https://github.com/parroty/exvcr/issues/107&quot;&gt;issue&lt;/a&gt; with the library and can really slow down your tests even with the async abilities of ExUnit.&lt;/p&gt;
&lt;h3&gt;Best Practices (Linting, Style, CI/CD)&lt;/h3&gt;
&lt;p&gt;The next major part of any software project is setting up your CI/CD system and any linters or style formatters. First I’ll discuss the linters and style formatters since this generally should be a part of the CI/CD pipeline. This is an area where I think Elixir really shines. It is incredibly easy to get both a linter and style formatter setup and integrated into your project pretty easily. For one with mix, Elixir comes with a built in formatter. All you need to do is define a &lt;code class=&quot;language-text&quot;&gt;formatter.exs&lt;/code&gt;(comes with &lt;code class=&quot;language-text&quot;&gt;mix new&lt;/code&gt; by default) file in the root of your project, and then you can just call &lt;code class=&quot;language-text&quot;&gt;mix format&lt;/code&gt; and your project will automatically get formatted based on your defined rules. This is a big win for Elixir because it means a majority(if not all) Elixir based projects have the same or a very similar code formats and are therefore easy to follow along and read. No spaghetti code to decipher or maintain. Secondly &lt;a href=&quot;https://github.com/rrrene/credo&quot;&gt;Credo&lt;/a&gt; is an open source static analysis tool for Elixir that is also easy to set up and run to make sure you are following best practices and keeping your code free of code smells and other issues. It just takes two steps of adding the library to your project’s dependencies and running &lt;code class=&quot;language-text&quot;&gt;mix credo&lt;/code&gt;. You will have to manually fix any issues that come up during a credo run though, whereas the formatter automatically formats your code for you.&lt;/p&gt;
&lt;p&gt;Next is CI/CD. Personally I have a lot of experience using &lt;a href=&quot;https://circleci.com/&quot;&gt;CircleCI&lt;/a&gt; so this is my goto solution because it’s relatively easy to set up for me and is free for public repos. One negative I encountered here is that the default configs for Elixir projects seem a little outdated or incorrect and I had to make some changes to get things to work. The pluses here though is that with &lt;code class=&quot;language-text&quot;&gt;mix format&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;mix credo&lt;/code&gt; I was able to easily put linting checks into my CI/CD process along with my tests. You can see the full CircleCI config &lt;a href=&quot;https://github.com/jrusso1020/alpaca_elixir/blob/master/.circleci/config.yml&quot;&gt;here&lt;/a&gt; in my repo. Lastly I just want to touch on briefly the ease of adding code coverage to Elixir based projects. The &lt;a href=&quot;https://github.com/parroty/excoveralls&quot;&gt;ExCoveralls&lt;/a&gt; library makes it relatively straightforward and free to set up for your open source Elixir project.&lt;/p&gt;
&lt;h3&gt;Documentation&lt;/h3&gt;
&lt;p&gt;Documentation isn’t an afterthought when writing Elixir it’s a first class citizen with builtin support. This has to be one of the best things for new developers coming to Elixir. You can easily write documentation alongside your code, even using markdown, and it will automatically generate beautiful html files, deploy, and host them for you when publishing a library. This leads to incredibly well documented libraries and a great developer experience for newcomers and veterans. It also allows any developer to easily correct documentation and extend it by creating a PR to update it within the repo. Although Elixir is a relatively small community and new library it provides incredible support for developers through this feature that allows anyone to easily learn and understand what a project or library is doing.&lt;/p&gt;
&lt;p&gt;Another huge benefit is that you can even run tests based on examples in documentation. This allows you two kill two birds with one stone. Write great documentation with real examples, and then test those examples directly to make sure they do indeed give you the desired results. All you have to do is add one line to your module’s test file like &lt;code class=&quot;language-text&quot;&gt;doctest YourModule&lt;/code&gt; and it will automatically run all of your examples to make sure they are valid.&lt;/p&gt;
&lt;h3&gt;Final Thoughts&lt;/h3&gt;
&lt;p&gt;In general I would say I think Elixir does a great job when it comes to developer productivity and friendliness. Even with a relatively small community, they have made it incredibly easy to start a project and follow best practices right out the gate so that you are learning the right way to write Elixir. This to me has been an issue with a lot of other languages I’ve used in the past. It’s hard to learn and follow best practices because there are seemingly dozens of ways people do things and no de facto standards in a lot of the tooling. Although I do think in general the tooling and libraries around Elixir may be lacking compared to more established languages, the Elixir core team has put the right fundamentals and building blocks in place for anyone to come in and hit the ground running when learning and writing Elixir. I personally have had a great experience writing Elixir so far and am excited to see the language and community continue to grow!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[External API's Should Allow for Free Dev Accounts]]></title><description><![CDATA[Recently I switched jobs and started coding in Elixir professionally. I feel proficient enough at work where most things are set up and…]]></description><link>https://boredhacking.com/dev-accounts-for-all/</link><guid isPermaLink="false">https://boredhacking.com/dev-accounts-for-all/</guid><pubDate>Sat, 30 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Recently I switched jobs and started coding in &lt;a href=&quot;https://elixir-lang.org/&quot;&gt;Elixir&lt;/a&gt; professionally. I feel proficient enough at work where most things are set up and running, it’s relatively easy to develop and add new features. However, I wanted to get a better understanding of setting up an Elixir project and tooling from scratch. So I decided to start simple and to try and write an Elixir wrapper for a 3rd party API. I thought it would be a simple enough project to get up and running before jumping into a more involved project. I had recently seen an article about &lt;a href=&quot;https://alpaca.markets/&quot;&gt;Alpaca&lt;/a&gt;, a service that allows you to “trade with algorithms, connect with apps, build services — all with [a] commission-free stock trading API.” So I took a look at their documentation and didn’t see an Elixir wrapper yet. I then did a quick google and saw one Elixir github project using it but it was years old and unfinished. Seeing as there weren’t any existing wrappers, I decided to give it a go. So I signed up for an account and started reading through their documentation. Alpaca actually offered a free sandbox environment for every account that you could use to issue API requests just as you would in real life, but with fake money. I thought this was fantastic, I could actually issue requests against an API without having to use real money. It cost me nothing, and could benefit countless developers in the future if I launch my API wrapper.&lt;/p&gt;
&lt;h2&gt;Why doesn’t everyone do this&lt;/h2&gt;
&lt;p&gt;This seemed like a win-win to me, but also something I rarely see in 3rd party software that offers an external API. Rarely is there a way for you to develop against an API unless you are already a paying customer. I’ve developed a couple of other language specific wrappers for API’s before and they always required signing some sort of contract or buying some sort of product before we could actually start developing against it. Wouldn’t it be great to not have to pay in order to test an API and develop against it? I think there are a few benefits of offering free developer accounts and a sandbox environment to developers&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;It allows open source developers to do your work for you. Sure you can build out wrappers for some core languages your team has expertise in, but there’s dozens of languages that people use and unless you are a very large company it is impossible to develop against them all. Why not let developers write wrappers for languages you can’t support. This could attract more customers for you in the end. Whether or not a language specific client exists for a given service could be the difference between choosing your service and another service (although obviously this is not always the case).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You get free debugging work. When adding new features to your API, developers can easily be the first to use it and find something that isn’t working as expected. Alerting your team to a bug hours, days, weeks, or even longer before you would have noticed it yourselves.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You get free security testing. Once again outside developers who have access to test accounts can perform security tests and penetration tests for you and find issues with your security way before you would ever find them. This is also possible in production but you open yourself up to even more rigorous testing with access to a developer account.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a larger community for your service. By allowing developers to have free test accounts you open up the community of users to not just paying customers but potential future paying customers and advocates. These developers may not need your service right at this moment but there may come a day in the future where their company needs your service, and they will know exactly who to recommend.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These are just a few of the reasons I can see why it would make sense to offer free developer accounts. Obviously though it does come with drawbacks. There’s the extra work of maintaining developer sandbox environments, however I think in general your own in house developers will already have this and if they don’t they probably should. Why not find a way to offer it to external developers in a safe way as well? Another drawback is that you may use this sandbox environment for testing new features, but this also could be something you would want external developers testing. Although you may not want them using new features right away, you can get free testing on beta features from external developers by allowing them to have access. You could also argue it’s a security risk, but I think an argument can also be made for the other side. That if you are doing it right there shouldn’t be a security risk. Your sandbox/staging environment should be completely separate from production, and accounts shouldn’t have access to each other.&lt;/p&gt;
&lt;p&gt;Lastly though this may not make sense for every company, some companies do have incredibly complex products that would be hard to offer a staging environment for. I recognize that I am making a generalization, and yes this isn’t necessarily something every product or company can and should do. Nevertheless, there are a lot of companies that could offer such a service and would greatly benefit from it.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Tips For Software Engineering Interviews]]></title><description><![CDATA[Background Late last year I decided to start interviewing for new jobs. It had been over two years since I had last interviewed, and…]]></description><link>https://boredhacking.com/tips-for-software-engineer-interviews/</link><guid isPermaLink="false">https://boredhacking.com/tips-for-software-engineer-interviews/</guid><pubDate>Sun, 26 Apr 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3&gt;Background&lt;/h3&gt;
&lt;p&gt;Late last year I decided to start interviewing for new jobs. It had been over two years since I had last interviewed, and although I had been working and performing interviews for my employers this doesn’t directly translate into keeping up your interview skills(although it does help). So I came up with some better my preparation methods which I discussed in a &lt;a href=&quot;/preparing-for-software-engineering-interviews/&quot;&gt;previous post&lt;/a&gt;, and I also came up with some tips and guidelines to help me perform better during interviews.&lt;/p&gt;
&lt;h3&gt;During Interviews&lt;/h3&gt;
&lt;p&gt;Throughout my interview process I came across four different types of interviews, and although you may encounter slightly different versions of these or take home assignments as well, I believe that these 4 types of interviews encompass most interviews. The first of which is a general HR phone screen, which is when a hiring manager or recruiter will ask you questions about your background and experiences, as well as give you more information on the company. Another type of interview I encountered was behavioral interviews. Behavioral interviews normally come during the on site round and are performed by engineering managers or VP’s of engineering. Since these are very similar to the HR phone screen, I will group my tips for both of these interview types. Coding challenges generally come as a screening process between the HR call and the onsites, but you will most likely also encounter at least one if not more of these once you come on site. Also system design interviews will most likely occur onsite as well, assuming you are not a new grad which in that case you may not be given this type of interview. Lastly, you will most likely have a coffee or lunch break once on site which will be a more laid back time for you to see more into the culture of the company and get your questions answered. Rarely will these types of interviews really factor into the decision, but they are still important and should be utilized as well as possible.&lt;/p&gt;
&lt;h4&gt;Coding Challenges&lt;/h4&gt;
&lt;p&gt;Check out my previous post about &lt;a href=&quot;/technical-software-interview-tips/&quot;&gt;Technical Software Engineer Interview Tips&lt;/a&gt; for information on how to prepare and perform better in coding challenges.&lt;/p&gt;
&lt;h4&gt;HR Phone Screens and Behavioral Interviews&lt;/h4&gt;
&lt;p&gt;Behavioral interviews are sometimes an afterthought for most engineers because the technical interviews are more feared and given more weight, but I think they deserve some preparation and thought as well. This can sometimes be the make or break for candidates and I have seen candidates ace technical challenges but still be rejected due to doing poorly in behavioral interviews. In my previous post I wrote about prepping for these types of interviews by outlining some common questions like “tell me about yourself”, “why are you leaving your current role”, “what are you looking for in your next role”, etc. as well as outlining a matrix of common question topics and projects that you encountered such issues on. Make sure to always reread these and adapt them slightly before your interview. If you prep ahead of time you can hopefully answer any question you encounter during these types of interviews. When it comes to phone screens, feel free to have a document with your prepared answers out in front of you so that you can easily reference them during the call. A slight difference between the phone screen and on site behavioral interview is that generally the onsite will be done by a more technical person in the organization. Although you should go into technical detail for the HR screen, sometimes you may want to keep it more high level technically in these interviews. Know your audience and know when you are giving too much information and confusing your interviewer. You want them to clearly understand what the problem was and how you solved it. However, with the on site go into more detail. Interviewers will generally want to know you clearly understood the problem and did your research before picking a solution. Don’t be too general when answering questions, if your answer sounds like something anyone could have said in response to that question then you aren’t giving enough information. You want to be driving this conversation with your answers. Your answer should tell a story where you lay out the problem you encountered, why it was a problem and how it relates to the question, how you went about finding a solution or solutions, what solution you picked and why, and what the final outcome was. Make sure you are painting a clear picture of how this situation answers the question.&lt;/p&gt;
&lt;p&gt;I would also use my preparation document to write down any questions that came up during the call that I wanted to ask so I wouldn’t forget them, or write down questions prior to the call. Feel free to take notes and write down what your interviewer is saying as well so you can look back and reference this information. I would always ask about the interview process and the company during these calls, then write down this information so I could look back later and compare it against other companies. Make sure you have at least a few thoughtful questions specific to the company before phone screen interviews so you can show you have looked into the company, but also feel free to generate questions during the conversation.&lt;/p&gt;
&lt;h4&gt;System Design Interviews&lt;/h4&gt;
&lt;p&gt;Make sure that at the onset of the interview you ask as many questions as possible about the system and what it’s requirements are such as # of requests per second or minute. Every system is different and it’s requirements will be different, sometimes # of requests per time period may not always make sense so think it through. But you will need to make some assumptions in order to get through the interview properly. Make sure you always talk through these assumptions and make sure the interviewer is in agreement. Also make sure that you understand the question at hand, it is important in any technical interview to make sure you are solving the right question. The interviewer will generally try their best to help you during these interviews though. System design interviews generally lend themselves to being more collaborative than algorithms and data structures. So make sure to listen to your interviewer and work with them. Talk through your system and make sure to touch on tradeoffs and alternatives. It’s important to show that you are considering multiple options and why you came to your current solution. The interviewer will generally ask clarifying questions if you don’t talk through alternatives, so even if you forget to do this on your own it’s important to be able to talk through your solution and why you picked it. Go into as much detail into the alternatives and your solution as possible. The difference between a solid yes and yes is generally how well a candidate can talk through alternatives and how knowledge they are on different aspects of the system. A common mistake I have made and seen made during these interviews is scaling the solution too quickly. It’s important to talk about some of the initial scaling optimizations you can make and then if they aren’t enough for the requirements talk about some larger scale changes that can be made.&lt;/p&gt;
&lt;p&gt;In general I would say the most important things to do during system design interviews (assuming you are prepared) are to work with your interviewer but stay in control and lead and then to make sure to talk through alternatives and rationale. These are necessary for designing systems on the job and are the main contributing factors to passing this interview assuming your system solves the problem.&lt;/p&gt;
&lt;h4&gt;Onsite Lunches&lt;/h4&gt;
&lt;p&gt;Onsite lunches are generally a time for you as the candidate to unwind and learn more about the company and its culture. There isn’t really much preparation here, but make sure you take this time to get any pending questions answered. Think about what is most important to you in your new role and make sure the company fulfills those needs during this time.&lt;/p&gt;
&lt;h3&gt;After Interviews&lt;/h3&gt;
&lt;p&gt;I would say there are two things I would recommend doing after an interview. First, if you were unable to answer the question or if you were unsure about something make sure you figure out what you did wrong and how you can do better in the future. Spend some time going through the question and researching the best solution.&lt;/p&gt;
&lt;p&gt;However, my second bit of advice is to make sure to unwind and not dwell on the past. There is nothing you can change now except the future. So make sure to figure out what you did wrong, but also make sure you give yourself some time to relax and recharge. Interviews, especially onsite interviews are incredibly stressful and anxiety inducing. Do something you enjoy (and preferably doesn’t involve coding) to let your mind recover. You don’t want to burn yourself out while you are actively interviewing, so make sure you are doing your best to stay healthy mentally and physically so you can perform to the best of your ability always! Continually stressing and practicing will hurt you in the long run if you don’t slow down every once in the while and let your mind rest.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Technical Software Engineer Interview Tips]]></title><description><![CDATA[Background Late last year I decided to start interviewing for new jobs. It had been over two years since I had last interviewed, and…]]></description><link>https://boredhacking.com/technical-software-interview-tips/</link><guid isPermaLink="false">https://boredhacking.com/technical-software-interview-tips/</guid><pubDate>Mon, 17 Feb 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3&gt;Background&lt;/h3&gt;
&lt;p&gt;Late last year I decided to start interviewing for new jobs. It had been over two years since I had last interviewed, and although I had been working and performing interviews for my employers this doesn’t directly translate into keeping up your interview skills(although it does help). So during my preparation which I discussed in a &lt;a href=&quot;/preparing-for-software-engineering-interviews/&quot;&gt;previous post&lt;/a&gt; I came up with a gameplan to help me perform better during technical interviews. I definitely don’t think I am a technical interview master like some of the people you see on youtube and on blog posts, but these methods definitely helped me to perform better.&lt;/p&gt;
&lt;h3&gt;Algorithms and Data Structures Coding Challenges&lt;/h3&gt;
&lt;p&gt;As mentioned during my previous post, I felt it was important to come up with a game plan for all of my coding challenges. Previously I felt like I would just go into technical interviews preparing for questions but when I was in the actual interview I never seemed to follow any set procedure. This would lead me to getting stuck and not being able to find a way out. So in order to combat this and make sure I always had a method where I could keep making progress I came up with the following 7 point plan. This plan may not work completely for everyone, but feel free to create your own or adapt mine to your style.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Restate the problem back to your interviewer in your own words, make sure you understand the question, and ask any clarifying questions.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I find that the first step to solving a question is making sure that you completely understand the question.This may seem basic, but you would be surprised at how easy it is to misunderstand the question and solve the incorrect problem. Remove any personal doubt that you understand the expected input and output. Also by restating it you may find things you didn’t see when initially reading/being told it. Your interviewer may also be nice enough to correct you if you ask if your restatement of the question is correct. However, they may not so it is important that you reread the question and make sure you are solving the right question. Sometimes candidates misunderstand the initial question and don’t spend time clarifying it, so they end up solving the wrong question. Often the interviewer won’t recognize this right away so you will spend most of your time solving a slightly different or incorrect question and then you will be left with little or no time to solve the correct version of the question. Spend a little extra time at the beginning to make sure you are solving the correct question.&lt;/p&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;&lt;strong&gt;Work through a couple of simple examples of the question, making sure to explain exactly what you are doing as you do it&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You may not always automatically see a solution to a technical question and that is okay. Start off by working with a simple example input with a simple expected answer. A lot of the time they may even give you example input and output. Feel free to work through this example mentally in front of your interviewer. If the example is slightly longer or more complex, make sure to simplify it down. You don’t want to spend too much time verbally going through the question. This should be quick so that you can spend most of your time coding.&lt;/p&gt;
&lt;p&gt;Start from the input and verbally work to an output, stating exactly how you are solving the problem to the interviewer. Using this method you should start to see a way you can solve this in code. However, it may not always be completely clear from one round of this how you can go from the spoken version to the code version. Maybe your example problem was not complex enough, feel free to do this more than once if necessary using slightly different inputs or statements of the problem. Don’t just solve the same problem over and over again because the odds of seeing it differently with the same input are not high. But if you solve the same problem with different inputs, you may see a pattern or method common to both that you can use. Just make sure not to spend too much time on this part.&lt;/p&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;&lt;em&gt;(OPTIONAL)&lt;/em&gt; &lt;strong&gt;Write a couple of simple tests at the beginning&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I made this step optional because in practice I never really wrote tests before writing code. However, by doing step 2 I would generally come up with at least 1 test assertion that I would use later. Some companies have a large focus on Test Driven Development which involves writing tests before actually coding up a solution. If interviewing for organizations like this it might be wise to write a few simple tests before coding, however remember you only have a certain set of time. Prioritize finish the coding solution.&lt;/p&gt;
&lt;ol start=&quot;4&quot;&gt;
&lt;li&gt;&lt;strong&gt;Talk through a potential solution at a high level, ask for feedback and if it seems like a reasonable approach&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;After working through the problem and coming to a potential solution I could code, I would restate this algorithm and ask my interviewer if that seemed like a good approach. Sometimes I would even write it out in pseudocode here and use those comments to drive my coding and structure. This can be incredibly helpful for yourself to get a quick self review and catch any potential gotchas or edge cases. Also it allows your interviewer to potentially call out any gotchas or edge cases. They may not always give you much feedback though and just say it seems reasonable, but you could potentially save yourself some debugging time by catching something during this step.&lt;/p&gt;
&lt;ol start=&quot;5&quot;&gt;
&lt;li&gt;&lt;strong&gt;Implement your approach, making sure to talk though what you are doing at each step. Feel free to break the problem up and test it at each step before moving on&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Finally the main attraction, time to code. Follow your pseudocode or vocalized approach you stated in step 4. Feel free to break the problem up into subproblems and code and test those individually. Sometimes for more complicated questions, I would make sure I was getting the expected result after each part of the implementation. This way I could fix any small bugs or issues before moving too far. This can help because if you run into a bug at the end it may be hard to find the problem. Lastly make sure you are talking through your implementation so that your interviewer can follow along. You want to make sure you keep the interviewer engaged and they understand what you are doing. Think of it as a paired programming session, where you are working with your interviewer not for them. You want to make sure your implementation is clear and approachable.&lt;/p&gt;
&lt;ol start=&quot;6&quot;&gt;
&lt;li&gt;&lt;strong&gt;Test, debug, repeat&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Your interviewer isn’t just going to take your word that your solution works. Once you believe your code is ready, write a simple test and make sure you get the expected outcome. If you don’t pass the test case then debug it using breakpoints or print statements(whatever is faster for this case), until you get the desired outcome and have your test passing. After you get the initial test passing try writing some more tests including for edge cases and follow this approach of debugging until all your tests pass.&lt;/p&gt;
&lt;ol start=&quot;7&quot;&gt;
&lt;li&gt;&lt;strong&gt;Ask the interviewer if they think your solution looks okay, or if they have any questions for you&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Lastly once your solution is well tested, ask your interviewer if your solution looks alright or if they have any questions for you. They may ask you why you chose to do something one way or another and make sure you talk about the tradeoffs of each and why you chose your route. They may also ask if there are any optimizations you could make, so make sure you inspect your code and see if you could use any smarter data structures or approaches to solve the problem now that you have an answer.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Preparing for Software Engineering Interviews]]></title><description><![CDATA[Background Late last year I decided to start interviewing for new jobs. It had been over two years since I had last interviewed, and…]]></description><link>https://boredhacking.com/preparing-for-software-engineering-interviews/</link><guid isPermaLink="false">https://boredhacking.com/preparing-for-software-engineering-interviews/</guid><pubDate>Sun, 16 Feb 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3&gt;Background&lt;/h3&gt;
&lt;p&gt;Late last year I decided to start interviewing for new jobs. It had been over two years since I had last interviewed, and although I had been working and performing interviews for my employers this doesn’t directly translate into keeping up your interview skills(although it does help). So in order to prepare for and perform well during my interviews I did a few things before my interviews which I will outline in this post and hopefully help some other engineers through their interview process. I definitely don’t think I am a technical interview master like some of the people you see on youtube and on blog posts, but these methods definitely helped me to perform better and feel less anxious before, during, and after interviews.&lt;/p&gt;
&lt;h4&gt;Sidenote: How to Find Jobs You Like&lt;/h4&gt;
&lt;p&gt;First I just wanted to briefly touch on some of the things I did to find potential employers I was interested in, since I believe that a lot of engineers(and other professionals) may want to start looking for a new job but have no idea where to apply. I believe it is important to always keep up with other companies and be looking for companies you are interested in even if you are happy at your current job. I did not apply to any companies for over two years, but I made sure to keep up with what was happening in my industry. This allowed me to keep a running list of companies and industries in my head that I would be interested in working for when the time came to look. I believe an important part of job searching is finding companies that interest you, so that if you get the offer it’s an easy decision to accept. I try my best to stay up to date in the tech world by reading blog articles and tech news articles, and I believe this among other things helped set me up for a quick and focused job search that led me to a job I was happy and excited for.&lt;/p&gt;
&lt;p&gt;However, even if you don’t have a running list of companies and industries you find interesting, I think it’s important to spend some time at the beginning of your job search to define what you value in your next role. What size company do you want to work for, what type of work or product is interesting to you, is there upward mobility, what industry or industries are you interested in, what would you like to get out of your next job, and what type of team would you like to work with are some questions you could ask yourself. By answering some questions about what you are looking for in your next job you can simplify your search and find companies that fulfill all or as many of your answers as possible.&lt;/p&gt;
&lt;p&gt;Equipped with a list of companies and specific industries, I was able to quickly apply and start the process with companies I knew I would want to work for. Because of this I was able to apply directly to companies and reach out to recruiters which I believe can help speed up the process. Also if you use hiring marketplaces like &lt;a href=&quot;https://hired.com/&quot;&gt;Hired&lt;/a&gt; and &lt;a href=&quot;https://www.vettery.com/&quot;&gt;Vettery&lt;/a&gt;, you can set your job search characteristics and get more companies you are interested in to reach out to you. A lot of times people apply to any jobs they see and this can lead to you starting the interview process with a lot of companies at the same time, many of which you don’t really want to work for. Interviewing is an incredibly time consuming task, so I believe it is important to make sure you have a focused search that allows you to spend your time wisely and prepare well for interviews you want to do well in. By being better prepared for applying, I was able to keep my initial company search list short and move quickly through the interview process with a few companies I thought I would be happy to work for and therefore accept the jobs right away.&lt;/p&gt;
&lt;p&gt;Something to note is that if you have a friend or acquaintance at a company you want to work for I highly recommend getting a referral because this can help speed up the time to initial phone screening and getting your resume seen. Even if you don’t know someone at a company sometimes people are willing to help out potential candidates so feel free to reach out to someone at a company you like on LinkedIn and see if they are willing to tell you about the company and potentially refer you.&lt;/p&gt;
&lt;h3&gt;Before Interviews&lt;/h3&gt;
&lt;p&gt;Although I do believe there are things you should do before, during, and after interviews to maximize your performance, prepping is most likely the most important because if you prep correctly then you will perform to your best ability during the interview. And if you perform to the best of your ability that’s all you can ask for out of an interview. Here are some of the things I did to prepare for interviews.&lt;/p&gt;
&lt;h4&gt;Read &lt;a href=&quot;https://www.amazon.com/Cracking-Coding-Interview-Programming-Questions/dp/0984782850&quot;&gt;&lt;em&gt;Cracking the Coding Interview&lt;/em&gt;&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;For anyone who doesn’t know about &lt;em&gt;Cracking the Coding Interview&lt;/em&gt; it is basically a holy book when it comes to Software Engineering/Coding interviews. I originally read it back in college during my initial job search but it had been a while since I looked through it. It basically lays out a bunch of the fundamentals of performing well in technical interviews as well as has a bunch of practice questions across technical categories. I highly recommend owning a copy of this book even if you aren’t actively looking for a job because I believe every software engineer should go through it at least once. It can also help you on the other side of the interview table to better ask questions and get ideas for questions. I recommend looking through the chapters and finding the most relevant ones for you or ones you need to improve the most in, since you may not need every type of question for certain positions. I don’t want to give too much away because I think this is an important book that should be read on it’s own, but there are a couple of chapters that talk about what to do before the interview and behavioral questions that I will focus on for this post. I recommend reading these especially since these will help you prepare and perform well in nontechnical interviews, which will help you get to the technical interview. Also if you make it to the on site you are more than likely going to have a round of behavioral questions as well.&lt;/p&gt;
&lt;h4&gt;Outline and Answer Behavioral Questions&lt;/h4&gt;
&lt;p&gt;I think it’s important to not only prep for technical questions but also make sure you have answers to some basic behavioral questions. Before I had any HR screening calls, I made an interview prep document where first I outlined a simple answer to the “tell me about yourself” question. In this outline I followed a simple approach. Start off by saying your current role and company, including a brief description of what that company does(just a few words). Next I moved to a brief(1-2 sentences) description of what originally got me into software engineering and what I studied in college. This may not be necessary for everyone and I did not always say this part, but since I am still fairly early on in my career I felt it was relevant to include. After that I would talk about my past roles and what I did at those companies, spending more time on my current role. Lastly if I felt it was needed, I would talk a little bit about my interests outside of work and how I became interested in or found the company I was talking too.&lt;/p&gt;
&lt;p&gt;Next based on the behavioral question chapter in &lt;em&gt;Cracking the Coding Interview&lt;/em&gt;, I setup a matrix with a few potential behavioral topics for three different projects I worked on. I don’t want to completely give this away since the book outlines this, but I will go over the concept. There are a few different types of behavioral questions you may encounter that are based on past experiences and how you handled them. If you can outline answers to these topics of questions across multiple different projects you can then use this as a study guide before behavioral interviews. I would recommend making sure these examples are as concrete as possible and clear. If you have any friends who work as software engineers or recruiters, try bouncing these answers off of them and seeing if they think they are clear. You want to make sure you are completely answering the question with specific examples. A good sign you haven’t completely answered the question is if the interviewer continues to probe you on the question or asks you for another example. You should use other interviews to tweak or change your answers if need be.&lt;/p&gt;
&lt;p&gt;Lastly I would also recommend laying out answers to any questions you think they may ask you. Some questions are “why are you leaving your current job?” or “what are you looking to get out of your next job?”. Another especially important question you could have answers for is what are some of your weaknesses. All too often people don’t have strong answers to this question and it shows they haven’t thought deeply about what they could do to improve themselves. I believe it is important for someone to always be looking for ways to get better, and having the self-awareness to know where you could improve is important for this. Try to create answers to as many possible questions so that you are better prepared. Put on your interviewer hat and think about what questions you might ask a potential candidate. Also I would come up with a list of possible questions to ask your interviewer. Interviewers will always leave time for you to ask questions, and you should use this time to the best of your ability. Come up with smart and thoughtful questions that give you more insight into the company and whether or not you would be happy there. Make sure the company matches what you are looking for in your next role.&lt;/p&gt;
&lt;h4&gt;Come up with a game plan for technical questions&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://media.giphy.com/media/Jszr4owyso6Xo9wjWT/giphy.gif&quot; alt=&quot;game plan gif&quot;&gt;&lt;/p&gt;
&lt;p&gt;During my prep I came up with a simple 7 step approach to solving all technical questions. This may not work completely for every person, but I think it is important for you to come up with your own game plan for solving technical questions. This way when you get stuck or feel uncertain, just stick to the game plan to keep moving forward and unblock yourself. Make sure your game plan has methods to unblock yourself. It’s important to always keep moving during technical interviews because you only have so much time. In some interviews if you can clearly show your ability to programmatically work through a problem, even if you don’t finish it, you can still pass. Feel free to use mine or adapt it. I will go over these 7 steps in my next post about &lt;a href=&quot;/technical-software-interview-tips/&quot;&gt;Tips for Software Engineering Interviews&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;Do your research&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://media.giphy.com/media/1SwSneBv946CZVYaNm/giphy.gif&quot; alt=&quot;research gif&quot;&gt;&lt;/p&gt;
&lt;p&gt;Do your research on the company, it’s interview process, and technical interview processes in general. Make sure you understand what the company does, what products they have launched recently, the role in general, any blog posts they have posted(or if they even have a blog), etc. It is important that you are able to clearly outline reasons why you want to work for the company and that you have done your research because this shows interest to your potential future employer. They want people excited and engaged in their company.&lt;/p&gt;
&lt;p&gt;It is also important to do your research on the interview process at each company you interview with. Make sure to look at glassdoor interview reviews and see what other people are saying. Although you should take glassdoor reviews with a grain of salt because it generally is where applicants who had bad experiences will go to, it is important to still recognize that these candidates had those experiences and there may be some problems at the company. However if this is a concern this is something you can bring up with during the HR portions of the process and see how they are addressing these concerns. I think the more reliable part of glassdoor is to look at past questions that candidates have been asked and make sure you practice these questions. Some companies will continue to ask the same questions for a little while, and you may also see a question on one company’s profile that another company will ask you (this happened to me). However glassdoor isn’t the only place to find interview questions anymore, so do some googling on the company’s interview process and see if you can find other resources as well.&lt;/p&gt;
&lt;p&gt;Lastly I think an incredibly important part of prep is to do research on interview processes in general and different types of questions. I watched loads of youtube videos about interview processes, questions, and methodologies for solving questions. As well as read dozens of blog posts on performing well in interviews. In today’s world there are more and more resources popping up every day in multiple different mediums(video, written, spoken) for one topic or another including technical interviews(meta: including this post). Use these to your benefit and make sure you see what other people are saying about the process you are currently in. This led me to my 7 step algorithm, and definitely made me a better and more informed interviewer.&lt;/p&gt;
&lt;h4&gt;Practice (yes we are talking about practice, sorry &lt;a href=&quot;https://www.youtube.com/watch?v=7Z4zfMWzvqw&quot;&gt;Allen Iverson&lt;/a&gt;)&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://media.giphy.com/media/3oEjI105rmEC22CJFK/giphy.gif&quot; alt=&quot;allen iverson talking about practice&quot;&gt;&lt;/p&gt;
&lt;p&gt;I think this should be pretty self explanatory that the best way to get better at technical interviews is to practice as many technical questions as possible. However, it is important that you practice in real life situations. Act like each practice question is being asked to you by a real person and you have a set time to solve it. Use your game plan you came up with to solve each practice question. If you practice like it’s the real thing you will perform better when the interview comes. This is the same for any practice and reminds me of a quote by Vince Lombardi that “Practice doesn’t make perfect, perfect practice makes perfect.” Make sure you aren’t just going through the motions when practicing, but make sure you are actually trying to solve the question to the best of your ability. It can also help you to perform better when practicing. When I didn’t follow my game plan for solving practice questions I would perform worse and have a harder time coming to a solution then when I followed the game plan like it was the real thing. Lastly just to touch on some resources for finding interview questions, you can use &lt;em&gt;Cracking the Coding Interview&lt;/em&gt;, &lt;a href=&quot;https://leetcode.com/problemset/all/&quot;&gt;Leetcode&lt;/a&gt; (I recommend only easy and medium questions because you will rarely ever get a hard level question in an interview), and youtube videos. These were the three main sources that I used, but there are definitely more out there you could use.&lt;/p&gt;
&lt;p&gt;There was also a video(s) on youtube which outlined 10 important coding topics to understand and you could use to answer almost any technical coding interview question. And I say almost because I don’t believe you necessarily need to use one or more of these topics for every type of interview question, but they can help with most. You can find the videos that discuss these topics &lt;a href=&quot;https://www.youtube.com/watch?v=r1MXwyiGi_U&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://www.youtube.com/watch?v=zHczhZn-z30&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Depth First Search&lt;/li&gt;
&lt;li&gt;Breadth First Search&lt;/li&gt;
&lt;li&gt;The matching parenthesis problem&lt;/li&gt;
&lt;li&gt;Using hash tables&lt;/li&gt;
&lt;li&gt;Pointer manipulations&lt;/li&gt;
&lt;li&gt;Reversing a linked list&lt;/li&gt;
&lt;li&gt;Sorting fundamentals&lt;/li&gt;
&lt;li&gt;Recursion&lt;/li&gt;
&lt;li&gt;Custom data structures (object oriented programming)&lt;/li&gt;
&lt;li&gt;Binary Search&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;Practice System Design Interviews&lt;/h4&gt;
&lt;p&gt;Before this round of interviewing, I had never gone through a system design interview either as an interviewer or interviewee. The last time I had interviewed I had been in college and most companies don’t require new grads to go through system design interviews since they generally lack this real world experience. So this was a new type of interview for me and something I spent pretty much all of my time working on once I had gone through a couple of technical phone screens and moved to onsites. I will say I think the best preparation for system design interviews is actually building real world systems. Therefore make sure in your current role you take every opportunity to build new systems. However, realistically this isn’t something that everyone can always do in their current role. Nevertheless, spend as much time as you can understanding your companies current systems such as how they work, where they are limited, what are some incremental improvements that could be made, ask questions to senior engineers and tech leads about the systems, etc. Another thing you can do is to read blogs and tech posts about other companies’ systems and what they are doing. Look at industry leaders and see how they are building systems, why, and what for, because more likely than not they are going to be doing it correctly.&lt;/p&gt;
&lt;p&gt;Nevertheless, these passive learning experiences don’t completely prepare you for what to expect in a system design interview. Another big problem is that different companies have to build different systems based on their needs and you probably aren’t going to be exposed to every type of system at your day job. You can constantly learn about real world systems and build great ones, but still fail a system design interview if you don’t prepare correctly and know what to expect. In order to prepare for the system design interview I personally did a few things. First I read through the chapter in &lt;em&gt;Cracking the Coding Interview&lt;/em&gt; about system design interviews and attempted the practice problems outlined there as well as went through their solutions. The other main thing I did was google common system design interviews and watch youtube videos where they went through common system design questions. These were incredibly helpful to quickly see a bunch of new and different systems you wouldn’t normally be exposed to at one single company. The biggest take away I got from all my preparation is that you need to be comfortable coming up with multiple possible solutions to a part of a system and discuss the trade offs. Know the differences and know how different things scale. A lot of people will also never build systems that need to scale to hundreds of thousands or millions of concurrent users, and sometimes these are questions that can come up in a system design interview.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;I hope that someone comes along and finds this interesting. I get incredibly anxious and stressed when it comes to technical interviews, which is a weird thing for me because I almost never felt that way in school. So before I started this interview process I tried my best to remove as much stress and anxiety as possible. I will say my first technical interview gave me a lot of anxiety but after I did one I felt less anxious because I could see my game plan work in action. By sticking to my gameplan, I was able to get to onsites with every company I interviewed with. Look for my follow up post on &lt;a href=&quot;/technical-software-interview-tips/&quot;&gt;Technical Software Interview Tips&lt;/a&gt; where I go into detail on my game plan I used for coding challenges.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Always Follow Orange Cords]]></title><description><![CDATA[“Always Remove Orange Cords” Recently I came across the following interview with Chief Product Officer Gijo Mathew at VTS. In this interview…]]></description><link>https://boredhacking.com/always-follow-orange-cords/</link><guid isPermaLink="false">https://boredhacking.com/always-follow-orange-cords/</guid><pubDate>Mon, 23 Dec 2019 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;“Always Remove Orange Cords”&lt;/h2&gt;
&lt;p&gt;Recently I came across the following &lt;a href=&quot;https://www.insightpartners.com/blog/7-questions-with-cpo-gijo-mathew&quot;&gt;interview&lt;/a&gt; with Chief Product Officer Gijo Mathew at &lt;a href=&quot;https://www.vts.com/&quot;&gt;VTS&lt;/a&gt;. In this interview, Gijo brings up a principle of his that he calls “Always Remove Orange Cords”. Gijo tells an anecdote of an orange extension cord that one day appears in the company’s office lobby. No one seems to care about this random extension cord, until someone new walks into the building one day and follows it only to find out it isn’t plugged into anything and serves no purpose. Gijo then goes on to say how he looks for “orange cords” in his companies, especially when first starting to remove old and outdated processes that no longer make sense or are useless.&lt;/p&gt;
&lt;h2&gt;Always Follow Orange Cords&lt;/h2&gt;
&lt;p&gt;Gijo’s principle made a lot of sense to me and made me quickly think about how it can be applied to software development. However, I don’t think it’s always necessary to remove “orange cords” though. However, I think it’s very important to always follow “orange cords” and trace it back to the source so that you can understand its purpose and why it’s there. Only then can you know it’s use and whether or not its purpose is still necessary. I believe that following “orange cords” will not only make you a better engineer but also greatly benefit your company as a whole and setup future engineers for success. If you and other members of your team are actively searching out and removing unnecessary things it will keep things cleaner and more maintainable. Orange cords can come in all shapes and sizes, so it’s important to not think anything is too big or too small to possibly be unnecessary and removed. Let’s look at a few different examples of “orange cords” you can come across in software development that need to be removed.&lt;/p&gt;
&lt;h3&gt;Lines of Code&lt;/h3&gt;
&lt;p&gt;The first type of “orange cords” I want to discuss are as simple as a single line of code. Over time lines of code can easily become deprecated or useless. Functions change and functionality changes as new features are developed. A common example can occur when handling errors or one off cases like in defensive programming. Maybe there is some function you call that occasionally raises an error. Then at some point the underlying error is fixed or handled within the function yet your original code remains unchanged. This can lead to unnecessary code that stays around after it is no longer needed and confuses developers or gives them false information about what can occur from the underlying function.&lt;/p&gt;
&lt;p&gt;Another example of lines of code that can become obsolete or unnecessary are if/case statements, especially ones involving other function or API calls. You may have if/case statements to handle an API’s response in certain cases. This can become especially common when there are different versions of API’s or in the process of updating an API. However, after a bit of time all cases may fall into one singular case and the if/case statement may become obsolete. It is necessary to keep track of these and remove the unnecessary statements, which will simplify your code.&lt;/p&gt;
&lt;p&gt;One final example I want to think about for lines of code that represent orange cords are feature flags or a/b tests. It is common for organizations to use feature flags to quickly turn on and off features for users or to use a/b tests to turn on and off features/experiments for cohorts of users. This is an important task of data driven organizations who want to test things quickly and be able to rollback changes quickly. However, organizations will eventually come to a conclusion on one solution at some point making the feature flag or a/b test code unnecessary. The organization will generally hardcode the final solution and remove the feature flag or the other experiment. Nevertheless there are times I’ve encountered where this step is forgotten, for any number of reasons, and the feature flag or a/b test mechanisms are relied on to make sure all users have the same experience. This can be avoided though by recognizing when a feature flag or a/b experiment’s time has ended and removing the unnecessary code that is no longer needed.&lt;/p&gt;
&lt;h3&gt;Functions or Modules&lt;/h3&gt;
&lt;p&gt;Functions, methods, modules or whatever your language decides to call them are incredibly useful and necessary in production code bases. Without going into too much detail why these abstractions are necessary, some reasons for abstractions like these are organization, reusability, ease of testing, and extensibility but you can read more about this &lt;a href=&quot;https://www.learncpp.com/cpp-tutorial/why-functions-are-useful-and-how-to-use-them-effectively/&quot;&gt;here&lt;/a&gt;. Nevertheless, these too can become unnecessary orange cords that need to be removed from your codebase at some point when they are no longer being used.&lt;/p&gt;
&lt;p&gt;It is quite common to need functions at one point but at some point have the functionality change or add the same functionality to another abstraction that will handle it from now on. In these cases your old function is no longer necessary but sometimes it remains around in the codebase. I’ve seen many developers wary of removing code old code just in case things need to be reverted. In these cases we leave around this extra function instead of deleting it and future developers gloss over it thinking it is important for some reason or another or maybe used in a place they aren’t touching. It is important to delete code as soon as it becomes unnecessary and is no longer in use because it becomes increasingly less likely it will happen as time goes on. Other developers will be less inclined to remove it unless they take the proper time to get the proper context and remove it.&lt;/p&gt;
&lt;h3&gt;Files&lt;/h3&gt;
&lt;p&gt;Files and all the code within them can become orange cords very easily. I saw this very common orange cord in a frontend codebase. There were dozens of old components in their files that had become obsolete over the years as new components with new functionality or designs were created, or as old features were removed. It was especially confusing when many of the files had the same names but existed in different directories or had very similar names. It became increasingly harder to find the correct and current version of the component. A simple change in the design could take hours instead of minutes when coming to a company that hadn’t been touched in a while, because you had to search for the correct and current version. Nevertheless, this is not just something that can happen in frontend codebases but in any codebase. As development continues in any codebase, it is common for old classes or services within files to be replaced by newer ones or have their functionality removed entirely. This can lead to the code within a file never being used in the codebase again, but it was left there by someone unsure of when or how to remove it. It is important for code to be deleted from a codebase once it is obsolete. As I outlined it can make your job as a developer more difficult when there are a bunch of unused files remaining in a project and you unnecessarily search through them. Also, allowing old unused files to remain in a codebase can increase the size of the overall application which although at first may not be an issue, it can become a problem down the line when the size of the application matters. This is especially true for frontend applications. Remember if you are using version control it is always possible to revert changes or look back in history to find code that has been removed and put it back.&lt;/p&gt;
&lt;h3&gt;Applications and Systems&lt;/h3&gt;
&lt;p&gt;The next level of orange cords and last I’ll discuss are applications or entire systems. There is a common theme here of things that become obsolete and forgotten but I want to highlight even apps and systems can become orange cords. Sometimes apps are replaced by newer versions or broken into microservices and monoliths become unused. Then there’s the case that even entire systems can be replaced by new systems. An example might be a logging system that gets replaced by a newer, faster more robust logging system. Or another example is a third party system that is brought in house or vice versa, and sometimes it can be forgotten to delete the unused system. This can become a problem especially when using both systems for some time before fully transitioning to the new one. Still, in extraordinary cases maybe a system becomes completely obsolete without even realizing it, hopefully this is never the case, but here especially you may find yourself with an orange cord that is never used without knowing it.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;With all of these examples it is easy to see why I liken them to orange extension cords that are unplugged and can be removed. As time goes on and no one removes it, it will eventually come up to one developer to take time to properly follow the orange extension cord to its source and see that is is no longer in use and can be removed. However, the longer the extension cord goes unfollowed the longer the cord will become because it’s history and time in general goes on. More and more commits and documents will have to be traversed to get to the beginning of time when it was created and when it became obsolete. Nevertheless, this is an important job and something good developers should take the time to do. Not only will it clean up your code base and your systems, but it will also make your fellow developers lives easier. There’s also some cases where it can save you or your company money in more ways than one. Hopefully looking at all these different examples have shown you that orange cords can come in all shapes and sizes and therefore you should always be on the lookout for them. You should strive to always take the time to understand every bit of code, every function, every file, app, system, etc. that you come across and what it’s purpose is. You will have to put more time into your initial feature development to understand everything around you, but as time goes on this will actually save you time because you will have to do less searching. The initial upfront work you will do will make you a faster and better developer, able to easily jump into a project or feature request because you don’t need to spend as much initial investigation for each one. Hopefully this guide will help you identify orange cords that can be removed, make yourself a better contributor, and help out your teammates and future teammates. Remember to always follow orange cords please!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Gatsby Plugin Updates Are Annoying]]></title><description><![CDATA[Disclaimer Gatsby is a great framework that I utilize to build this website. Plugins are a vital part of that solution and I enjoy how they…]]></description><link>https://boredhacking.com/gatsby-plugin-updates/</link><guid isPermaLink="false">https://boredhacking.com/gatsby-plugin-updates/</guid><pubDate>Sun, 17 Nov 2019 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Gatsby is a great framework that I utilize to build this website. Plugins are a vital part of that solution and I enjoy how they can expedite development of Gatsby websites. There are loads of great things I can say about Gatsby and its plugins. However, I think it’s important to also realize the downfalls of technologies you like and use. So although this post is negative, I would definitely recommend Gatsby to others and advocate for it (in the right situations).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Gatsby is a framework that utilizes React to build blazing fast statically generated websites and apps. Gatsby utilizes a plugin system to extend it’s API for specific use cases. These plugins allow you to easily borrow a Node.js package that someone else developed to solve the same issue you might be encountering, allowing you to quickly build in complex functionality to your Gatsby site. There are pros and cons to this plugin ecosystem. Obviously a large pro is the ability to leverage common behaviors and quickly build features into your sites that someone else has already solved. However, a rather annoying can occur with Gatsby Plugins if you use a service like Dependabot to automatically check and update your dependencies in your app. For those who are not aware, Dependabot will check your dependency files for any outdated or insecure requirements and then automatically open up pull requests updating each dependency when needed. Shameless plug, &lt;a href=&quot;https://dependabot.com/&quot;&gt;Dependabot&lt;/a&gt; is a great service and since it’s acquisition by Github, you can use Dependabot pro for free through Github so check it out to keep your dependencies up to date! However, Dependabot set to live updates plus Gatsby plugins can lead to a rather annoying experience. Gatsby maintains a large number of their own plugins and a lot of them get updated at the same time as you can see by the Dependabot PR’s opened in the below picture&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/8deab8113427b3af2ab37ec0e2ee1517/efb68/gatsby-plugins-updates1.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 73.64864864864865%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABYlAAAWJQFJUiTwAAACU0lEQVQ4y41Uy27TUBT0x7PiA1ixZcuCiq4qJBBCKhKPVqJQETdxHDt++z5sx6/rYe4NEkKUtJaOxkp8j2fmzLFX1gK67dCwlG4wTjOGcXI42fthgFQafT9ASM3nWhhjsOB4iVHh6ffneHLzDC+CM3hNd0BWVO5hW7b5NC/EA7oDm+kW/aFD12qopuOztftPqMZhKRVyUaMQAqpr4fXTiDhNsQ0jhPEeuzhBkuWIk9RhXpZ4fytx8U2iGyayH52CfviD02RczbOBZxZDSQpFUaKua1RVjbKseC8ghHTstkWHi5sWQTni1LUsC7zZzGSYYOXfkeUO2+0O601ADBFFMYo8R1WXePND491t4+zgSXf4vvJmMiyqEvE+QUqJCaU6TDNWDkmPdKPxKbAs6Vtvjmz+y3CZUVYV9mxom+R54bCgd4IvarWAn7Z4fa2wzgd30JgHGMZJgvU6cJI3QUgM4Yd7vPyY4dLXfLXBMC0Y5+VxHgolj4Pg6G1JKZDVCudXEp+D/i+Jywn/XEOzHIfyc+Uj4CDCXUTcMkIJvvgVVrHCYejhZwM2xfC79f3lGk5kmNOrvR0GvbMDidgsI0pRoWsUkkrj7Erhw6p1B80phh1XK6SHPj0MdjE2DLgte7+NUkaGLBON82uBTd4xzANablDX/1s25N44T4go+W69cZID5jCwW0PpdlMubhRefZU4jMYxmLnH5kQdY0MWVm7GyBRFQdmMDzfHxknzY3B51+ItQ91Pj5iy9UNI6RrmrmHp0K6g5O9932MvRgQcyMhdxQNT/gWG5HzJp3yobgAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;dependabot opening a lot of gatsby plugin updates&quot;
        title=&quot;&quot;
        src=&quot;/static/8deab8113427b3af2ab37ec0e2ee1517/fcda8/gatsby-plugins-updates1.png&quot;
        srcset=&quot;/static/8deab8113427b3af2ab37ec0e2ee1517/12f09/gatsby-plugins-updates1.png 148w,
/static/8deab8113427b3af2ab37ec0e2ee1517/e4a3f/gatsby-plugins-updates1.png 295w,
/static/8deab8113427b3af2ab37ec0e2ee1517/fcda8/gatsby-plugins-updates1.png 590w,
/static/8deab8113427b3af2ab37ec0e2ee1517/efc66/gatsby-plugins-updates1.png 885w,
/static/8deab8113427b3af2ab37ec0e2ee1517/c83ae/gatsby-plugins-updates1.png 1180w,
/static/8deab8113427b3af2ab37ec0e2ee1517/efb68/gatsby-plugins-updates1.png 2032w&quot;
        sizes=&quot;(max-width: 590px) 100vw, 590px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Sometimes the plugins are updated in the same day leading Dependabot to close the old PR’s and open new PR’s and closing the old outdated ones. This is pictured in the below image&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/0a898edd3739c714cdd3c383c04318cf/ee787/gatsby-plugins-updates2.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 78.37837837837837%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAABYlAAAWJQFJUiTwAAACT0lEQVQ4y31U2Y7TQBD0//8Ir4gVD4AEvPAAQpAVLMsKyOEzHl9zeZzEjoueThy0u3gtVdqeeErVU9UOqkZCaYNGKoZUmjEMRxzHkQEcMVIdjrR2HC/r90Dr/tVA2RbStNCEWmp0+wPcbo9aGShjUdFaVlnktYHULapGwbiOqoZpO5T0rKkq2t+TCCI0iJMUSZohzbbItjljmxdo6hIbofDyWuMu60jpiL4fWE0/DKx4qqyeJAbGWURxgpQIPdF0v80FyrKGNRJfNxpXC4PSDPAXn8J/rnEiTM5knsTXSWlZeUKFrLZ4fWNxk3SnjWc8JGdC27XcsifZetJzy0XhW66hlcJSWLy9tVgWe6byG+cQ6NZwm16lR+TJqYaJwCou0VACPi0d3v206A4zvd5TSC17dbkoIIqS2y4KgcVK4tV3g8r+O7fx9DMLJiyVxHITYR3GpCpDnFLLeY4PdxWefWwQVjt6uSd3e4rU0+DYSAr2aiKk1rlGCX6HW/yKChTS4Dpq8fGPhd31HJND/xjd7sD/BXvnkLGrvm3B8K1X1Qmt1fgWO3KZgu6Gi8sPr2Hw+SSFjsbMmzI5fQr52XU6TyklPq8tnn/RELqfzaE/Eh/uoKPRmxxmc3LBBvlJKcsCSe3w5keLFUcG55l9jH5SuKN55ck4B9u3K9hxIqUqmxopBfvFQmMRdrMtXwg1ndF6ExIiMiPGJoz4/jQ9AkaTaaLFFc3zutzPtnwJtu0c6rpBQ277z1dF9/5Z0ldE0fm6tsVt2uE9BVu5nvUdn5iUv/06ylShDpcwAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;dependabot reopening outdated pull requests&quot;
        title=&quot;&quot;
        src=&quot;/static/0a898edd3739c714cdd3c383c04318cf/fcda8/gatsby-plugins-updates2.png&quot;
        srcset=&quot;/static/0a898edd3739c714cdd3c383c04318cf/12f09/gatsby-plugins-updates2.png 148w,
/static/0a898edd3739c714cdd3c383c04318cf/e4a3f/gatsby-plugins-updates2.png 295w,
/static/0a898edd3739c714cdd3c383c04318cf/fcda8/gatsby-plugins-updates2.png 590w,
/static/0a898edd3739c714cdd3c383c04318cf/efc66/gatsby-plugins-updates2.png 885w,
/static/0a898edd3739c714cdd3c383c04318cf/c83ae/gatsby-plugins-updates2.png 1180w,
/static/0a898edd3739c714cdd3c383c04318cf/ee787/gatsby-plugins-updates2.png 2022w&quot;
        sizes=&quot;(max-width: 590px) 100vw, 590px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;And then Gatsby might update the same plugins a couple of days later, as you can see in the below picture if you look carefully&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/358f92e4e8586bae76d1fd29d908bd7e/ca98b/gatsby-plugins-updates3.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 68.24324324324324%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAABYlAAAWJQFJUiTwAAACDklEQVQ4y41T247TMBTM/38FH8AL8ICQEBIgeFlotUApvTf3xLFzsZ0mzaXDsUsXIe22WBqdRLEnc86MnUwUyEQJqRvkpUTbDTi0HUqpoQ7tueoaUipUqgazew/g+blmVEtZ23017Xd4kcPzA0RxYpGkDCnLwDJOEMjp++eVxItJgVx3GIYBfT/i2PX0PKKj2lM1MO9OLgu4no8gjBBGEfwgtDDkXAjUtcbEq/H6u0J5GGDW6YRH14k+OKWq4HkBkSWIk9QiIWSksCR1hdL4sNR4v9A4kjI6Zg8+hnEkhQURRlFsSQyZbZuqHzMECUeYa7yZadz7zVV1DworJS1hyphtkYscSpb4spN4/lWCqfGB6HSN7UIYZgw/5gss1lust3vMF2ssNztsXR9+RK3TT6b7Ci+nFVzeYOh7NG2P9vg4nEKSQjM3xpHS3GwlCKu0orhIuEzh1bTE3VahI0Lj8FNweCmw27tndyk+1u0wxNpLMXc55a1CRXm72zeYhe3tlsuLKZQ/kz1TheCkhtq818jUv1F5yuG/LpMB3kUZEZsIBaSWkUkVxabRBX5FCs8+FfgWNP+RQy3tzci4sHMzLpsbUuQ5AlHj7U+NVXputRtOtxVmucBytcFmt8eWcJmnURlnOSauwru5Rlh0lnS8RWhyGMepzaFRamaY/bnHB03XrW7xcVljZts1h64T/gZn6S4gsV8zwwAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;dependabot updating more gatsby plugins&quot;
        title=&quot;&quot;
        src=&quot;/static/358f92e4e8586bae76d1fd29d908bd7e/fcda8/gatsby-plugins-updates3.png&quot;
        srcset=&quot;/static/358f92e4e8586bae76d1fd29d908bd7e/12f09/gatsby-plugins-updates3.png 148w,
/static/358f92e4e8586bae76d1fd29d908bd7e/e4a3f/gatsby-plugins-updates3.png 295w,
/static/358f92e4e8586bae76d1fd29d908bd7e/fcda8/gatsby-plugins-updates3.png 590w,
/static/358f92e4e8586bae76d1fd29d908bd7e/efc66/gatsby-plugins-updates3.png 885w,
/static/358f92e4e8586bae76d1fd29d908bd7e/c83ae/gatsby-plugins-updates3.png 1180w,
/static/358f92e4e8586bae76d1fd29d908bd7e/ca98b/gatsby-plugins-updates3.png 1968w&quot;
        sizes=&quot;(max-width: 590px) 100vw, 590px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;All of these PR’s are from the repo that I use for this blog, which was started with the &lt;a href=&quot;https://github.com/gatsbyjs/gatsby-starter-blog&quot;&gt;Gatsby Starter Template&lt;/a&gt;. So this is a pretty basic site, and I’ve added a few more plugins myself. Generally there’s at least once a week where I get 10 PR’s opened by dependabot, and there’s some weeks where it happens multiple times a week or even a day. There was a period of time where I had two Gatsby repo’s I was maintaining and they shared a lot of plugins so this would occur in two different repos at the same time. Obviously if you have even more Gatsby repo’s you maintain this would continue to happen for all of them as well. This is a rather vicious cycle that consists of me having to merge in these PR’s one by one, rebasing them after I merge in one, until they are all merged in. This process normally takes quite some time because I have to wait for my CI to pass before I can merge in each PR after it’s rebased. When this happens multiple times a week this can take over an hour to merge in all the changes per repo.&lt;/p&gt;
&lt;h2&gt;Is there something Gatsby could do better?&lt;/h2&gt;
&lt;p&gt;There are things I can do to combat this and I will discuss those in a bit. But I am curious if there isn’t something Gatsby could do about this? Could they not release updates so often for all of their plugins? Is there a better way for them to manage their plugins so that you don’t need to update them all so often? It’s great to keep your dependencies up to date as much as possible to get new features, patch security risks, get performance updates, reduce maintenance of an old version, and many others. Nevertheless, there’s also some drawbacks like encountering bugs that haven’t been found yet, but let’s not go into too much detail on the negatives here. So I try my best to keep my dependencies up to date by utilizing Dependabot, but then it leads me into this annoying routine of merging in, rebasing, and waiting for PR’s. I will be honest and say I haven’t looked into the reason behind why so many of them get updated at the same time. This is something I plan to look into more, so that I can contribute a meaningful approach to a better solution if one is possible. I continue to manually update them though for the time being, even though it is a time consuming task.&lt;/p&gt;
&lt;h2&gt;Is there something I could do better?&lt;/h2&gt;
&lt;p&gt;There are a few different things that I have thought of that would make this better for myself. The first option would be to change my Dependabot settings so that I don’t get updates so often. However, this could still lead me to have to get around 10 PR’s opened at one time (or even more), just at less often intervals. This would also mean I wouldn’t be updating my dependencies as often which would lead me to miss out on the benefits I named above.&lt;/p&gt;
&lt;p&gt;One option could be to turn off dependabot for these updates or just update them all in one PR manually when I see the PR’s opened. What I mean by this is instead of merging in all of these PR’s one by one once they are opened, I could see them opened then manually run &lt;code class=&quot;language-text&quot;&gt;npm update&lt;/code&gt; in my project so I update all my outdated packages at once. Then just merge in this one new set of changes all at once instead of one by one. Dependabot would notice the packages were updated and the PR’s were out of date so then it would close them all. However, this probably isn’t the best practice for a number of reasons. One big reason is that if I update all of the packages at once and one of them introduces a breaking change I would need to roll back the updates and do them one by one anyways to see which one was the breaking change. This is probably not a good approach to use if I can avoid it.&lt;/p&gt;
&lt;p&gt;Another and more viable option would be to use a tool to automatically merge in these PR’s when they are up to date and passing CI. Dependabot should take care of automatically rebasing the PR’s when they get out of date which is great. There are a few tools out there form a quick search that can be integrated with Github or you could even use Github Actions to automatically merge in PR’s that match certain criteria. I’d be curious to hear more about any free options out there that people are using to do this, so please feel free to comment below and let me know of any such tools. I’d be happy to give them a try to try and get out of this annoying situation. I think this will most likely be my approach once I’ve found time to vet some different solutions and hopefully integrate it into my repo. Hopefully I can come back here and update this blog with a solution once I’ve implemented it and save anyone else from this annoyance who might encounter it.&lt;/p&gt;
&lt;h2&gt;My solution&lt;/h2&gt;
&lt;p&gt;After writing this post in full (but before posting) I stumbled upon a &lt;a href=&quot;https://dependabot.com/blog/automatic-pull-request-merging/&quot;&gt;Dependabot feature for automerging&lt;/a&gt; that I was not aware of before. I think a lot of my problems could have been solved had I done some proper googling earlier. You can turn on auto merging in your account settings which will then allow you to enable it on a per project basis. You can set the level of dependency updates that you want to merge in automatically and Dependabot will merge them in for you assuming all of your status checks pass. I’ll give this a go and see how things go, hopefully it saves me some time. But like I said, I would be curious to hear what other approaches people use for this as well. There may be drawbacks to this approach so I may revisit this post in the future for any updates.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[When should you use Gatsby?]]></title><description><![CDATA[Gatsby.js is one of the most popular frontend frameworks currently and a huge buzzword in frontend web development. For anyone who isn’t…]]></description><link>https://boredhacking.com/overusing-gatsby/</link><guid isPermaLink="false">https://boredhacking.com/overusing-gatsby/</guid><pubDate>Fri, 01 Nov 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://www.gatsbyjs.org/&quot;&gt;Gatsby.js&lt;/a&gt; is one of the most popular frontend frameworks currently and a huge buzzword in frontend web development. For anyone who isn’t aware of Gatsby.js yet, it is a frontend framework that allows you to develop a statically generated website using React. This allows you to get the development benefits of React, and also get the SEO, page load, etc. benefits of a statically generated website. Sounds great right? Well not so fast. I believe many people are too quick to reach for Gatsby when starting a new frontend application, and many people are using it in places where they really shouldn’t. I too was a victim of this thinking, and started a project with Gatsby that I really shouldn’t have (more on this in a bit). I have also heard of others including companies using Gatsby either when they could probably benefit better from another framework. Don’t get me wrong though I do really like Gatsby, this site is built using Gatsby! When Gatsby is used correctly it can be great. In this post I will try to go over some of the reasons and situations you should use Gatsby, but also outline some situations where you should not and you are better off gravitating to another framework like &lt;a href=&quot;https://nextjs.org/&quot;&gt;Next.js&lt;/a&gt;. These lists and ideas are definitely not exhaustive or the only opinion, but I think they are a good rule of thumb to go by. I may update this page as new things come to light from my and others experience.&lt;/p&gt;
&lt;h2&gt;My Mistake&lt;/h2&gt;
&lt;p&gt;Recently I needed to create an admin interface at work. I had started working with Gatsby when creating this blog and had really loved the experience. The idea that I can code in React and use all the libraries and techniques I’m used to, while also getting the benefits of a statically generated website is awesome. The plugin system for Gatsby is also very cool, and allows you to easily add in Gatsby plugins to get the functionality you would normally have to do a lot more setup for. I have experience with plain React and Create React App(CRA) as well as server side rendered(SSR) React using Next.js, but my first thought was to reach for Gatsby again to create this admin interface for a backend API that already had been started. This was a bad choice for a few reasons.&lt;/p&gt;
&lt;p&gt;Let me start by outlining some of the basic requirements for this admin interface.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Only authenticated users should be able to access any part of the application besides the login, forgot password, and reset password pages.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once you’ve logged in, there is minimal static content on the pages besides the navigation bar.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Almost all of the data on the page comes at render time and can be updated by user actions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;There are dynamic routes in the application for accessing resources that can be created in app.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SEO is not necessary because we only want our users to use this application, and therefore all bots should be disallowed.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Just from these few simple requirements I’m sure a lot of people will quickly be able to tell that Gatsby was not the right choice, but for those who can’t let me outline why Gatsby wasn’t a good choice. The first requirement requires me to make almost every single route in the application a client side only route. This means these routes are not statically generated and do not have corresponding index.html files. The third requirement further outlines this problem in that most of the data on the page comes at render time and is generated by an API and not during the build phase of the Gatsby application. Furthermore, user’s can update and create resources therefore creating more content for application which can’t be statically generated at build time. The last major reason that Gatsby was most likely not the best choice for this application was because I do not need any SEO benefits.&lt;/p&gt;
&lt;p&gt;I’ll go into more of the reasons when you shouldn’t pick Gatsby later on, so I won’t dwell on these too much for now. Basically all of these requirements should have led me to look at other frameworks or templates for my application. If I am being honest with myself, I had realized some of these drawbacks before starting the application and realized Gatsby may not be the best option. However, I thought it over and came to the conclusion that using Gatsby would be better than using CRA (normal react setup) or a framework like Next.js. My thought process behind this is I know a Gatsby app is still faster to load in the browser than a normal react application even if I’m not getting all the benefits of it being statically generated. And I knew deploying a Gatsby application on AWS (where we host all of our applications), is easier to do than deploying a Next.js application. This is because Next.js needs a server since it’s SSR, and therefore you either need to deploy a running server application on AWS and maintain/monitor it or you have to do some cleverness to get it to run serverless using Lambdas. Gatsby (and normal react applications) have a build process that results in a bundle or set of files that you can just put into an S3 bucket and put Cloudfront in front of it and be done. So I stayed with Gatsby for the faster load in the browser and the ease to deploy it. However, I eventually ran into a problem that would cause me to have to give up on using Gatsby for this application.&lt;/p&gt;
&lt;p&gt;While developing the application everything seemed to be going great. We are a small startup and I was developing as well as doing QA on it myself. So I would develop locally, write tests, check it locally, and then deploy to staging and quickly test the app there as well. Everything seemed to be going well, until the app had gotten to a good minimal place to be used by others and I started giving others access to staging to test and use it. This is when I started running more rigorous tests myself on staging to make sure everything was working as expected. I ran through all the basic functionality once and it seemed to be working great. However, I did some refreshes and realized something weird going on with the styling. After refreshing and checking the auth token in local storage, it went from the login page to the first authenticated route but the page was much smaller and located in a smaller div that made a box in the center of the page. After some debugging I realized it was putting the whole React component of the authenticated client side route, into the login page root div element. This caused the whole page to be rendered within the login box and be unusable. I checked this over and over locally in multiple scenarios and was unable to replicate it. It only existed in the staging environment. So I turned to the Gatsby issues to see if others were experiencing a similar issue. There were lots of people with CSS issues where they weren’t being applied correctly or they were mixing up classes. Originally I thought it might be this, but then I took a look at the &lt;a href=&quot;https://github.com/gatsbyjs/gatsby/tree/master/examples/client-only-paths&quot;&gt;Gatsby client side route example&lt;/a&gt; to see if I was doing anything wrong in the code. I couldn’t find anything different from my application, so I took a look at the &lt;a href=&quot;https://client-only-paths.gatsbyjs.org/&quot;&gt;hosted example&lt;/a&gt; (which has since been taken down). I noticed in this example that if I went to any page that wasn’t the home page and refreshed, that the styles from the home page were applied to the refreshed page instead of the appropriate styles because the root dom element was updated incorrectly. This seemed to be very similar if not the exact problem I was facing with my application which was basically all client side routes. So I opened up an issue on Gatsby’s github &lt;a href=&quot;https://github.com/gatsbyjs/gatsby/issues/17891&quot;&gt;here&lt;/a&gt;, and have still yet to hear anything from anyone.&lt;/p&gt;
&lt;p&gt;I couldn’t just wait for this problem to be figured out or try to solve it myself (without knowing Gatsby’s codebase), because who knows how long it has existed and how long it would take to solve. I needed to move quickly because this was a necessary part of our software architecture, and we needed to continue development. So begrudging thel solution I chose was to rewrite the application not using Gatsby. So I chose to rewrite the application using Next.js, which I also had used before and knew the file structure was very similar to Gatsby. The main differences to convert the application was to remove all the Gatsby methods and use built in Next.js methods instead, replace all the Gatsby plugin functionality that we needed, and setup the tests to work in the new project. The final difference would be getting the application deployed, which as stated previously required deploying a running server. All in all moving the app’s components and pages over, replacing the Gatsby methods with Next methods, and getting the app to run took about a day. Then getting the tests to run took about another day or so, and deploying the application took about half a day. However, the deployment went fairly quickly because we use Kubernetes, and all we had to do was set up our docker container and repo, our deployment files, and our Kubernetes cluster to deploy this new application. If I had gone with my gut and thought through it more, I could have started in Next.js from the beginning and none of this would have happened. Therefore, I thought it would be nice to outline my problem as well as some of the tell tell signs of when to/not to use Gatsby.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Disclaimer: All of this could have been found earlier if I had done more rigorous testing on staging from the beginning and is something I would normally do, but working alone and for a very small startup when trying to move fast I had forgone this more rigorous testing. So remember always rigorously test on staging.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;When you Should Use Gatsby&lt;/h2&gt;
&lt;p&gt;First let’s talk about some of the great places you should use Gatsby.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;For simple personal websites with a lot of content that doesn’t change too often.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Blogs (like this one!) which can be generated from markdown or are connected to a CMS and use GraphQL to build all the pages during build time.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Simple ecommerce sites with a limited set of items that will not continue to grow much over time.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Marketing websites with simple content or CMS backends that use GraphQL to build the pages.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Landing pages&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Business websites&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Any site where all or almost all the content is part of a CMS. One thing to note is in order to get the most out of Gatsby it is important to use GraphQL to generate the pages at build time.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;While this list is definitely not exhausted (and may be added to), I think these are some of the base cases when you should use Gatsby. I would say one major thing to note when Gatsby should be used is when you know what information is going to be on all or most of the pages at build time and you can easily/quickly rebuild the pages when something is added or changed. I say easily/quickly rebuild the pages because all though in some cases you may know what all of the pages are at build time and what will be on them, the larger your site grows the longer the build will take and the more you should think about not using Gatsby.&lt;/p&gt;
&lt;h2&gt;When you Shouldn’t Use Gatsby&lt;/h2&gt;
&lt;p&gt;Now let’s discuss some of the times where you probably shouldn’t use Gatsby.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Applications that are mostly behind authentication that can’t show data until the user is logged in (like my example above). If the authenticated pages are mostly static for some reason, then it might still be better to use Gatsby. But if the data on the pages changes per user then it is probably best not to use Gatsby.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Sites with a lot of dynamically generated routes, because you won’t get the benefits of statically generated pages if you don’t know them at build time&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Complex sites (like some large ecommerce sites), that are constantly adding new pages and content because these will quickly grow and have very large build times. Although a lot of ecommerce sites can use and do use statically generated sites, if build time becomes a problem it is most likely time to move away from statically generated sites like Gatsby.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Sites where most pages don’t get page data until the page is rendered in the browser. You will not get you statically generated page benefits if most of your data comes after the page is rendered&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Sites with CMS’s that change a lot. This also may not be an &lt;em&gt;always&lt;/em&gt; case, but if your site has a frequently updated CMS then Gatsby may not be a good option because the build step will slow down changes. Also if your site has a CMS but you don’t use GraphQL to build the pages, then you probably aren’t using Gatsby right and should look at another solution.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I would say two general rules on when you shouldn’t use gatsby are 1) When the site has a lot of dynamic or constantly changing pages/data that doesn’t remain constant 2) or when build times will grow exponentially over time and limit your deployment speed.&lt;/p&gt;
&lt;h2&gt;Alternatives&lt;/h2&gt;
&lt;p&gt;There are a number of alternative approaches you can use instead of Gatsby and when you should use them depends on your use case. There is always the general Create React App (Vanilla React) approach which is the simplest approach. You can SSR parts of your app or all of your app which will get you closer to if not all of Gatsby’s benefits. You can do this by either implementing SSR in your Vanilla React application yourself, or if you have the luxury/freedom of starting an app from scratch you can use a framework like Next.js. Next.js is a SSR framework for React very similar to Gatsby but it allows you to better handle more complicated applications that are sure to grow or have a lot of dynamic content. When Gatsby isn’t the best choice, there is a very good chance that Next.js will be a good alternative. Next.js allows you to make requests server side and then render server side which will speed up your applications load time and initial page render in the browser as well as give you SEO benefits, among many other benefits. I do not see Gatsby and Next as battling frameworks but instead as frameworks for different use cases, and I think it is important to note that. Once again this is not an exhaustive list of alternatives but if you are already familiar with React I think they are worth knowing about. I hope this post helps others avoid the problem I encountered, as well as bring some awareness to the different use cases and solutions available.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Automating Deploys to Kubernetes with CircleCI]]></title><description><![CDATA[There are multiple techniques and approaches for automating application updates to Kubernetes clusters. Different approaches offer different…]]></description><link>https://boredhacking.com/deploying-to-eks-circleci/</link><guid isPermaLink="false">https://boredhacking.com/deploying-to-eks-circleci/</guid><pubDate>Fri, 11 Oct 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;There are multiple techniques and approaches for automating application updates to Kubernetes clusters. Different approaches offer different benefits and complexity. In a &lt;a href=&quot;/deploying-to-eks-codeship&quot;&gt;previous post&lt;/a&gt; of mine, I outlined my first attempt at deploying updated applications to a Kubernetes cluster using codeship. In this approach I just updated the image running on the containers in the deployment using the kubectl set image approach. In this tutorial I will use template Kubernetes yaml files, and update the Kubernetes configuration for the application then apply the changes. I will outline this in more detail throughout this post. Two other approaches I have come across in research but have yet to try are 1) using Helm and Helm templates to update Kubernetes yaml files and deploy changes and 2) using a Gitops flow to store all of your Kubernetes configurations and files, update them on changes, and deploy those changes. Gitops workflow is a technique espoused by &lt;a href=&quot;https://www.weave.works/&quot;&gt;Weaveworks&lt;/a&gt;. I think this approach is something that interests me the most and I will continue to learn about and try to implement in the future. I’m always interested in learning more about Kubernetes and woudl be keen to hear about even more appraoches indviduals and organizations use. But for now let’s talk about using Kubernetes template yaml files.&lt;/p&gt;
&lt;h3&gt;Setting up your Kubernetes template files&lt;/h3&gt;
&lt;p&gt;I am going to skip over some details and make a few assumptions. My first assumption is that you have already created a Dockerfile for your application. Now once you are ready to deploy your application to your Kubernetes Cluster, we will need to prepare the template files that we will use to setup our Kubernetes configuration. In our case we have both a staging and production environment, so in our root application directory we make a &lt;code class=&quot;language-text&quot;&gt;.k8s&lt;/code&gt; folder for our templates. Then we create another directory &lt;code class=&quot;language-text&quot;&gt;templates&lt;/code&gt; within &lt;code class=&quot;language-text&quot;&gt;.k8s&lt;/code&gt; and here we place a &lt;code class=&quot;language-text&quot;&gt;staging.yml&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;production.yml&lt;/code&gt;. In the end you should have files setup like so&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;.k8s
-&gt;templates
--&gt;staging.yml
--&gt;production.yml&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now let’s take a simple deployment yaml file, and change it into a template that we can substitute values into on each deployment.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1
&lt;span class=&quot;token key atrule&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ConfigMap
&lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;config
  &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
&lt;span class=&quot;token key atrule&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;ENV_VALUE1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; value1
  &lt;span class=&quot;token key atrule&quot;&gt;ENV_VALUE2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; value2

&lt;span class=&quot;token punctuation&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; apps/v1beta1
&lt;span class=&quot;token key atrule&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Deployment
&lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment
  &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
&lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;replicas&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;matchLabels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
    &lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;containers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
          &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;TAG
          &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;containerPort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3000&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;envFrom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;configMapRef&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;config

&lt;span class=&quot;token punctuation&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Service
&lt;span class=&quot;token key atrule&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1
&lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;service
&lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; LoadBalancer
  &lt;span class=&quot;token key atrule&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;protocol&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; TCP
      &lt;span class=&quot;token key atrule&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;80&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;targetPort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In order to make it a template all you need to do is to make a few basic changes so that you can substitute environment variables from CircleCI into the template when deploying.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1
&lt;span class=&quot;token key atrule&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ConfigMap
&lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;config
  &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
&lt;span class=&quot;token key atrule&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;ENV_VALUE1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; $&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;STAGING_ENV_VALUE1&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;ENV_VALUE2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; $&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;ENV_VALUE2&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token punctuation&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; apps/v1beta1
&lt;span class=&quot;token key atrule&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Deployment
&lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment
  &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
&lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;replicas&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;matchLabels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
    &lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;containers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
          &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; $&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;AWS_REPOSITORY_URL&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;/$&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;REPOSITORY_NAME&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;$&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;CIRCLE_BRANCH&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;$&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;CIRCLE_BUILD_NUM&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;containerPort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3000&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;envFrom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;configMapRef&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;config

&lt;span class=&quot;token punctuation&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Service
&lt;span class=&quot;token key atrule&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1
&lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;service
&lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; LoadBalancer
  &lt;span class=&quot;token key atrule&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;protocol&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; TCP
      &lt;span class=&quot;token key atrule&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;80&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;targetPort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And just like that you have the staging template setup as staging.yml. You can recreate a similar production.yml for your production builds. If there is no change between your production and staging builds you can technically use the same template. However, you can see in the ConfigMap of the template &lt;code class=&quot;language-text&quot;&gt;STAGING_ENV_VALUE1&lt;/code&gt; which is a specific variable just for staging. Then in your production template you would get &lt;code class=&quot;language-text&quot;&gt;PRODUCTION_ENV_VALUE1&lt;/code&gt;. Next we will setup our CircleCI and our &lt;code class=&quot;language-text&quot;&gt;.config.yml&lt;/code&gt; for deployments.&lt;/p&gt;
&lt;h3&gt;Setting up CircleCI for deployments&lt;/h3&gt;
&lt;p&gt;Before setting up your &lt;code class=&quot;language-text&quot;&gt;.circleci/config.yml&lt;/code&gt; file I would recommend making sure you setup all your necessary environment variables in CircleCI. In our case we use AWS’s ECR and EKS services so we need to set up the AWS credentials in CircleCI including the Access Key Id and Secret Access Key. There is an AWS Credentials location you can put these or you can set them yourselves as Environment variables. Make sure the account credentials you are using are setup to deploy to both ECR and EKS and it has the proper Kubernetes permissions. You can set the Kubernetes permissions through the RBAC permissions of the cluster to give it access but I will not cover this here. Other important variables to make sure you set in CircleCI are Docker image repository url and repository name which are used by the build to save the new Docker Image. &lt;code class=&quot;language-text&quot;&gt;CIRCLE_BRANCH&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;CIRCLE_BUILD_NUM&lt;/code&gt; are given to us by CircleCI and all other variables are app dependent. Two environment variable that we have not seen yet but will need are the &lt;code class=&quot;language-text&quot;&gt;CLUSTER_NAME&lt;/code&gt; which is our Kubernetes cluster name and &lt;code class=&quot;language-text&quot;&gt;AWS_DEFAULT_REGION&lt;/code&gt; which is the AWS region of the cluster. We will need these later during deployment.&lt;/p&gt;
&lt;p&gt;Now let’s create the &lt;code class=&quot;language-text&quot;&gt;.circleci.config.yml&lt;/code&gt; file which will do the work of building our docker image and deploying our new application to our Kubernetes cluster.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2.1&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/node&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;10.15.3
    &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/app
    &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; checkout
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Update npm
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;sudo npm install -g npm@latest&quot;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;restore_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dependency&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;cache&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; checksum &quot;package.json&quot; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install npm
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; npm install
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;save_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dependency&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;cache&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; checksum &quot;package.json&quot; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; node_modules
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;save_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;repo&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Environment.CIRCLE_SHA1 &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; ~/app
  &lt;span class=&quot;token key atrule&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/node&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;10.15.3
    &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/app
    &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;restore_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;repo&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Environment.CIRCLE_SHA1 &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;restore_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dependency&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;cache&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; checksum &quot;package.json&quot; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Test code
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; npm test
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;persist_to_workspace&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/app
          &lt;span class=&quot;token key atrule&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; .

  &lt;span class=&quot;token key atrule&quot;&gt;build_image_and_deploy_staging&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/python&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3.7&lt;/span&gt;

    &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/app

    &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;attach_workspace&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/app

      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install awscli and gettext&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;base
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            sudo pip3 install awscli&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install aws&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;iam&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;authenticator
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            curl -o aws-iam-authenticator curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/aws-iam-authenticator
            chmod +x ./aws-iam-authenticator
            sudo mv ./aws-iam-authenticator /usr/local/bin/aws-iam-authenticator&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install kubectl
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/kubectl
            chmod +x ./kubectl
            sudo mv ./kubectl /usr/local/bin/kubectl&lt;/span&gt;

      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; setup_remote_docker

      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Login to repository and build docker image
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
            docker build -t ${AWS_REPOSITORY_URL}/${REPOSITORY_NAME}:${CIRCLE_BRANCH}-${CIRCLE_BUILD_NUM} .
            docker push ${AWS_REPOSITORY_URL}/${REPOSITORY_NAME}:${CIRCLE_BRANCH}-${CIRCLE_BUILD_NUM}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Prepare K8S templates
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $CLUSTER_NAME
            rm -rf .k8s/.generated &amp;amp;&amp;amp; mkdir -p .k8s/.generated
            for f in .k8s/templates/staging.yml
              do
              envsubst &amp;lt; $f &gt; &quot;.k8s/.generated/$(basename $f)&quot;
            done&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Deploy
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            kubectl apply -f .k8s/.generated/ --validate=true
            kubectl get pod&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;workflows&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;build-test-and-deploy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; setup
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;requires&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; setup
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;build_image_and_deploy_staging&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;requires&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; test
          &lt;span class=&quot;token key atrule&quot;&gt;filters&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token key atrule&quot;&gt;branches&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
              &lt;span class=&quot;token key atrule&quot;&gt;only&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; master&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;setup&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;test&lt;/code&gt; jobs that are listed here but can be changed for you specific app, in this case we used a simple node application as an example. The &lt;code class=&quot;language-text&quot;&gt;build_image_and_deploy_staging&lt;/code&gt; job is the bulk of this config and tutorial. At the bottom of the config.yml file you can see the workflow section that shows you need to run the &lt;code class=&quot;language-text&quot;&gt;setup&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;test&lt;/code&gt; jobs before building the image and deploying it. I will not cover this, but you can look at it to get an idea of the complete workflow. Now let’s go through the &lt;code class=&quot;language-text&quot;&gt;build_image_and_deploy_staging&lt;/code&gt; job bit by bit.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;build_image_and_deploy_staging&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/python&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3.7&lt;/span&gt;

  &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/app&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The main thing to note here is that we use a python docker image because we need the awscli command since we are deploying to ECR and EKS.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;attach_workspace&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/app&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;First we attach the workspace from our previous jobs so we can use the same checked out code and dependencies if any that have been installed. If you do not have any other jobs before this make sure you use the &lt;code class=&quot;language-text&quot;&gt;checkout&lt;/code&gt; command to checkout your code and do any other setup that is necessary.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install awscli and gettext&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;base
    &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
      sudo pip3 install awscli&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This installs the awscli command so that we can interact with ECR and EKS.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install aws&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;iam&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;authenticator
    &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
      curl -o aws-iam-authenticator curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/aws-iam-authenticator
      chmod +x ./aws-iam-authenticator
      sudo mv ./aws-iam-authenticator /usr/local/bin/aws-iam-authenticator&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now we download the &lt;code class=&quot;language-text&quot;&gt;aws-iam-authenticator&lt;/code&gt; utility so that we can authenticate our AWS credentials when interacting with EKS.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install kubectl
    &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
      curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/kubectl
      chmod +x ./kubectl
      sudo mv ./kubectl /usr/local/bin/kubectl&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The last bit of setup is to download the &lt;code class=&quot;language-text&quot;&gt;kubectl&lt;/code&gt; utility so that we can interact with our Kubernetes cluster.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; setup_remote_docker&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;From the &lt;a href=&quot;https://discuss.circleci.com/t/confused-about-what-setup-remote-docker-really-does/11469?gclid=EAIaIQobChMI28K-5JSV5QIVzZyzCh0eMAFaEAAYASAAEgIuNvD_BwE&quot;&gt;CircleCI website&lt;/a&gt; “When you run &lt;code class=&quot;language-text&quot;&gt;setup_remote_docker&lt;/code&gt;, we allocate a remote Docker engine. You are connecting to it via TCP. You can’t run Docker within Docker, as noted at the top of the documentation: For security reasons, the Docker Executor doesn’t allow building Docker images within a job space.”&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Login to repository and build docker image
    &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
      eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
      docker build -t ${AWS_REPOSITORY_URL}/${REPOSITORY_NAME}:${CIRCLE_BRANCH}-${CIRCLE_BUILD_NUM} .
      docker push ${AWS_REPOSITORY_URL}/${REPOSITORY_NAME}:${CIRCLE_BRANCH}-${CIRCLE_BUILD_NUM}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This command gets login credentials from ECR, then builds our Docker image and pushes it to our remote ECR repository. As you can see we use the same environment variables that we used in the template, and therefore are able to make sure we use the same Docker image when generating our Kubernetes deployment file from the template.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Prepare K8S templates
    &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
      aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $CLUSTER_NAME
      rm -rf .k8s/.generated &amp;amp;&amp;amp; mkdir -p .k8s/.generated
      for f in .k8s/templates/staging.yml
        do
        envsubst &amp;lt; $f &gt; &quot;.k8s/.generated/$(basename $f)&quot;
      done&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here we first configure our kubectl in this workspace to use our kubeconfig from our cluster. Without this we will not be able to interact with our cluster or issue commands to it. The next command removes any lingering generated deployment files just in case. Then we use the &lt;code class=&quot;language-text&quot;&gt;envsubst&lt;/code&gt; command to replace all the environment variables in our &lt;code class=&quot;language-text&quot;&gt;staging.yml&lt;/code&gt; template and generate a new Kubernetes deployment config.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Deploy
    &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
      kubectl apply -f .k8s/.generated/ --validate=true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The final command applies our generated Kubernetes deployment file while validating it. You can add a command after this to check for the deployment’s progress if you would like. But with this command we have just successfully deployed our changes to our Kubernetes cluster.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Mocking Sentry in Jest and Gatsby]]></title><description><![CDATA[When testing a React based application that uses Sentry.io it is necessary to mock Sentry. You shouldn’t be making API calls to report…]]></description><link>https://boredhacking.com/mock-sentry-in-jest/</link><guid isPermaLink="false">https://boredhacking.com/mock-sentry-in-jest/</guid><pubDate>Mon, 23 Sep 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When testing a React based application that uses &lt;a href=&quot;https://sentry.io/&quot;&gt;Sentry.io&lt;/a&gt; it is necessary to mock Sentry. You shouldn’t be making API calls to report errors during your test, and more importantly you shouldn’t need to load Sentry in your test environment anyways. However, if Sentry is missing or not setup in the testing environment this may cause your tests to fail, raising a &lt;code class=&quot;language-text&quot;&gt;ReferenceError: Sentry is not defined&lt;/code&gt;. Before discussing how to mock Sentry in your test, if you are adding Sentry to your Gatsby.js project, please follow &lt;a href=&quot;https://www.gatsbyjs.org/packages/gatsby-plugin-sentry/&quot;&gt;this great tutorial&lt;/a&gt; and which uses the plugin &lt;code class=&quot;language-text&quot;&gt;gatsby-plugin-sentry&lt;/code&gt;. This easy to use plugin adds Sentry to your project and only loads it in certain environments, in my case “staging” and “production”.&lt;/p&gt;
&lt;p&gt;Once you’ve setup Sentry if you need help adding Jest to your Gatsby.js application you can follow another tutorial &lt;a href=&quot;https://www.gatsbyjs.org/docs/unit-testing/&quot;&gt;here&lt;/a&gt;. This will go through all of the initial setup to get Jest working with your Gatsby.js application. However if you use the global &lt;code class=&quot;language-text&quot;&gt;Sentry&lt;/code&gt; object created by &lt;code class=&quot;language-text&quot;&gt;gatsby-plugin-sentry&lt;/code&gt; in your code this will cause your tests to error out and fail. The solution around this is to mock the global &lt;code class=&quot;language-text&quot;&gt;Sentry&lt;/code&gt; object so that your tests can pass. So lets take a look at how we can setup your application to accomplish this.&lt;/p&gt;
&lt;p&gt;First you must create a new file in your root directory, let’s call it &lt;code class=&quot;language-text&quot;&gt;setup-test-env.js&lt;/code&gt;. This file can be used to setup globals and other things needed for you Jest tests after the tes environment has been setup. Then in your &lt;code class=&quot;language-text&quot;&gt;jest.config.js&lt;/code&gt; you must add the line &lt;code class=&quot;language-text&quot;&gt;setupFilesAfterEnv: [&quot;&amp;lt;rootDir&gt;/setup-test-env.js&quot;]&lt;/code&gt; like so&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// jest.config.js&lt;/span&gt;
module&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;exports &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token string-property property&quot;&gt;&quot;^.+\\.jsx?$&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;lt;rootDir&gt;/jest-preprocess.js&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;moduleDirectories&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;node_modules&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;lt;rootDir&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;moduleNameMapper&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token string-property property&quot;&gt;&quot;.+\\.(css|styl|less|sass|scss)$&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;identity-obj-proxy&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token string-property property&quot;&gt;&quot;.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;lt;rootDir&gt;/__mocks__/file-mock.js&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;testPathIgnorePatterns&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;node_modules&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;.cache&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;transformIgnorePatterns&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;node_modules/(?!(gatsby)/)&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;globals&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;__PATH_PREFIX__&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;testURL&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;http://localhost&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;setupFiles&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;lt;rootDir&gt;/loadershim.js&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;setupFilesAfterEnv&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;rootDir&gt;/setup-test-env.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will ensure that the setup file is loaded in after the test environment is loaded. This is necessary because we need certain packages and values to be setup and loaded before we mock Sentry(like the Sentry package).&lt;/p&gt;
&lt;p&gt;Now in &lt;code class=&quot;language-text&quot;&gt;setup-test-env.js&lt;/code&gt; we need to mock &lt;code class=&quot;language-text&quot;&gt;Sentry&lt;/code&gt; globally so that we can use it in our code run by our tests and not get an error that &lt;code class=&quot;language-text&quot;&gt;Sentry&lt;/code&gt; is not defined. This can be accomplished with the following line’s of code&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// setup-test-env.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; Sentry &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;@sentry/browser&quot;&lt;/span&gt;

global&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Sentry &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Sentry
jest&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;mock&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;@sentry/browser&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And just like that you should be able to run your tests and mock the global &lt;code class=&quot;language-text&quot;&gt;Sentry&lt;/code&gt; value so that your code is able to call the global &lt;code class=&quot;language-text&quot;&gt;Sentry&lt;/code&gt; object without raising any error’s or making API calls.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Deploying a Gatsby Application to an S3 Bucket Using CircleCI]]></title><description><![CDATA[Edited 2020-12-26 to split up build and deploy steps to run build on every branch So you’ve created your first Gatsby.js application and you…]]></description><link>https://boredhacking.com/deploy-gatsby-s3-circleci/</link><guid isPermaLink="false">https://boredhacking.com/deploy-gatsby-s3-circleci/</guid><pubDate>Thu, 15 Aug 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;Edited 2020-12-26 to split up build and deploy steps to run build on every branch&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So you’ve created your first Gatsby.js application and you’d like to deploy it on AWS instead of Netlify like everyone else. I personally chose AWS because this was an application for work and the rest of our stack is hosted on AWS as well. My approach (and many others) to deploying applications is to first do it manually and then automate it using CI/CD such as CircleCI. So in this tutorial I will start with the initial manual process, which is documented elsewhere as well, and then move to the automated process.&lt;/p&gt;
&lt;h3&gt;Initial Manual Deployment&lt;/h3&gt;
&lt;p&gt;I won’t be going over the whole process in detail but I will try and touch on everything briefly. This &lt;a href=&quot;https://itnext.io/static-website-over-https-with-s3-cloudfront-gatsby-continuously-delivered-b2b33bb7fa29&quot;&gt;blog&lt;/a&gt; does a good job of going over some of the details I will rush through. What I did first was buy a domain name for my application through Route53. Then I setup an S3 bucket on AWS that is public and setup to host a static website. It is necessary for it to be public so that you can use Cloudfront as a CDN in front of it. I followed the following &lt;a href=&quot;https://www.gatsbyjs.org/docs/deploying-to-s3-cloudfront/&quot;&gt;tutorial&lt;/a&gt; provided by Gatsby’s website to setup everything manually initially. Through this I used the &lt;code class=&quot;language-text&quot;&gt;gatsby-plugin-s3&lt;/code&gt; package to simplify deployment to S3. You can install this using &lt;code class=&quot;language-text&quot;&gt;npm install --save gatsby-plugin-s3&lt;/code&gt; and then adding the following to your &lt;code class=&quot;language-text&quot;&gt;gatsby-config.js&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token literal-property property&quot;&gt;plugins&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;resolve&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;gatsby-plugin-s3&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;bucketName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;my-website-bucket&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next you must add the following to your &lt;code class=&quot;language-text&quot;&gt;package.json&lt;/code&gt; so that you can use the &lt;code class=&quot;language-text&quot;&gt;npm run deploy&lt;/code&gt; command to deploy your application to S3&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token string-property property&quot;&gt;&quot;scripts&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
   &lt;span class=&quot;token string-property property&quot;&gt;&quot;deploy&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;gatsby-plugin-s3 deploy -y&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In order to deploy your application to an S3 bucket programmatically you need to setup an AWS IAM user with the correct privileges. The easiest is to have admin privileges on the account you can also add a policy to it that looks like the following&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string-property property&quot;&gt;&quot;Version&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string-property property&quot;&gt;&quot;Statement&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token string-property property&quot;&gt;&quot;Effect&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Allow&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token string-property property&quot;&gt;&quot;Action&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;s3:*&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token string-property property&quot;&gt;&quot;Resource&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;*&quot;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will give the account full access to all S3 actions and resources, if you would like you can limit it to just the bucket you are using as well for added security.&lt;/p&gt;
&lt;p&gt;Once you have this account setup, you can configure it in your environment as your default or set the environment variables in your current environment. I prefer the latter since I have multiple AWS IAM users for different operations. This can be accomplished by running the following commands in your current terminal shell&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;export AWS_ACCCESS_KEY_ID=your_access_key_here
export AWS_SECRET_ACCESS_KEY=your_secret_key_here&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now that you have set these variables you can run the command &lt;code class=&quot;language-text&quot;&gt;npm run build &amp;amp;&amp;amp; npm run deploy&lt;/code&gt; to automatically build and deploy your Gatsby application to your S3 bucket. After running this command you should be able to go to your S3 bucket url and see your application. However, there are a couple of more steps I personally did to make my application a little robust. I created a Cloudfront distribution connected to my S3 bucket, make sure to use your Static Website Hosting Endpoint as the CloudFront origin. Once you have setup the Cloudfront Origin you can then create an SSL/TLS certificate in ACM and connect it to your Cloudfront distribution and set your CNAME to your custom domain.&lt;/p&gt;
&lt;p&gt;I know I briefly went through these parts rather quickly, but I think there are plenty of other tutorials to explain this part of the setup and I have tried to link to a couple of them. The next step from here is setting up automated deploys to your S3 bucket via CircleCI&lt;/p&gt;
&lt;h3&gt;Automated Deployments&lt;/h3&gt;
&lt;p&gt;Okay let’s start but just looking at the &lt;code class=&quot;language-text&quot;&gt;.circleci/config.yml&lt;/code&gt; file that will be located in your project.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2.1&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/node&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;15.5.0
    &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/anakin
    &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; checkout
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install Yarn 2
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            curl -o- -L https://yarnpkg.com/install.sh | bash
            yarn set version 2.4.0&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;restore_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; checksum &quot;yarn.lock&quot; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install Dependencies
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            yarn install --immutable&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;save_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Save Yarn Package Cache
          &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; checksum &quot;yarn.lock&quot; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; ./.yarn/cache
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;save_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;repo&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Environment.CIRCLE_SHA1 &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; ~/anakin
  &lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/node&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;15.5.0
    &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/anakin
    &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;restore_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;repo&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Environment.CIRCLE_SHA1 &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;restore_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; checksum &quot;yarn.lock&quot; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Build
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            yarn run build&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;persist_to_workspace&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .
          &lt;span class=&quot;token key atrule&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; .
  &lt;span class=&quot;token key atrule&quot;&gt;deploy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/node&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;15.5.0
    &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/anakin
    &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;attach_workspace&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Deploy
          &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
            yarn run deploy&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;workflows&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2.1&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;build_and_deploy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; dependencies
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;requires&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; dependencies
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;deploy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;requires&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; build
          &lt;span class=&quot;token key atrule&quot;&gt;filters&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token key atrule&quot;&gt;branches&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
              &lt;span class=&quot;token key atrule&quot;&gt;only&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; main&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see there are three jobs in the config file. The first downloads the dependencies, the second builds the project, and then the final handles the deploy step. Once you create this file you have to go into CircleCI and set your environment variables. Under Settings in the CircleCI project, you can go to AWS Permissions and set your access key and secret key that were created for the manual steps. I also set another environment variable for the aws region of my bucket using the AWS_DEFAULT_REGION key.&lt;/p&gt;
&lt;p&gt;Now let’s take a look at our config file piece by piece. The first job looks like so&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/node&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;15.5.0
  &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/anakin
  &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; checkout
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install Yarn 2
        &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
          curl -o- -L https://yarnpkg.com/install.sh | bash
          yarn set version 2.4.0&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;restore_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; checksum &quot;yarn.lock&quot; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Install Dependencies
        &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
          yarn install --immutable&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;save_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Save Yarn Package Cache
        &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; checksum &quot;yarn.lock&quot; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; ./.yarn/cache
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;save_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;repo&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Environment.CIRCLE_SHA1 &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; ~/anakin&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This uses the docker image that is the same node version used locally for development and sets the working directory. Then in the steps first we checkout the code. Then install yarn and set the proper version. Next we try to restore the cache for our yarn packages if it exists for this same &lt;code class=&quot;language-text&quot;&gt;yarn.lock&lt;/code&gt;. Next we install all of our dependencies. The final two steps are saving caches for our yarn downloaded dependencies and the repository to be used by the next jobs.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/node&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;15.5.0
  &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/anakin
  &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;restore_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;repo&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Environment.CIRCLE_SHA1 &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;restore_cache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; yarn&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;packages&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;v1&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; .Branch &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; checksum &quot;yarn.lock&quot; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Build
        &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
          yarn run build&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;persist_to_workspace&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .
        &lt;span class=&quot;token key atrule&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; .&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This code restores the caches we created in the last step so we don’t need to checkout code again or reinstall modules. It then builds the project. Lastly it persists the workspace to be used by the next job. This is necessary since the build step creates the artifacts we will use for deployment.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;deploy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; circleci/node&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;15.5.0
  &lt;span class=&quot;token key atrule&quot;&gt;working_directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ~/anakin
  &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;attach_workspace&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Deploy
        &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
          yarn run deploy&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Lasty we have our deploy step which attaches the workspace from the previous step. It then runs the deploy script to s3.&lt;/p&gt;
&lt;p&gt;Finally we have the workflow which handles only deploying on pushes to our main branch.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;workflows&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2.1&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;build_and_deploy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; dependencies
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;requires&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; dependencies
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;deploy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;requires&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; build
          &lt;span class=&quot;token key atrule&quot;&gt;filters&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token key atrule&quot;&gt;branches&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
              &lt;span class=&quot;token key atrule&quot;&gt;only&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; main&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see we run the &lt;code class=&quot;language-text&quot;&gt;dependencies&lt;/code&gt; job every time followed by the &lt;code class=&quot;language-text&quot;&gt;build&lt;/code&gt; job, but we only run the &lt;code class=&quot;language-text&quot;&gt;deploy&lt;/code&gt; job when the branch is the main branch and we require the &lt;code class=&quot;language-text&quot;&gt;build&lt;/code&gt; job to be run first. Running the &lt;code class=&quot;language-text&quot;&gt;dependencies&lt;/code&gt; job and &lt;code class=&quot;language-text&quot;&gt;build&lt;/code&gt; job on every branch allows us to catch build errors before they are merged to main. You can also add in a test job to occur after setup and to be run every time, and be required by &lt;code class=&quot;language-text&quot;&gt;deploy&lt;/code&gt; but that’s a relatively simple addon. Another add on is to handle pushing to either staging or production based on the branch, but that is also covered by other documentation.&lt;/p&gt;
&lt;p&gt;Now if you have setup your project on CircleCI, you should be able to push to your master branch and see that your application is deployed to your S3 bucket!&lt;/p&gt;
&lt;h3&gt;Additional Resources&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://www.gatsbyjs.org/docs/deploying-to-s3-cloudfront/&quot;&gt;https://www.gatsbyjs.org/docs/deploying-to-s3-cloudfront/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://itnext.io/static-website-over-https-with-s3-cloudfront-gatsby-continuously-delivered-b2b33bb7fa29&quot;&gt;https://itnext.io/static-website-over-https-with-s3-cloudfront-gatsby-continuously-delivered-b2b33bb7fa29&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://circleci.com/blog/automate-your-static-site-deployment-with-circleci/&quot;&gt;https://circleci.com/blog/automate-your-static-site-deployment-with-circleci/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://circleci.com/docs/2.0/deployment-integrations/&quot;&gt;https://circleci.com/docs/2.0/deployment-integrations/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://medium.com/@zlwaterfield/circleci-s3-upload-dbffa0956b6f&quot;&gt;https://medium.com/@zlwaterfield/circleci-s3-upload-dbffa0956b6f&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.freecodecamp.org/news/how-to-set-up-continuous-deployment-to-aws-s3-using-circleci-in-under-30-minutes-a8e268284098/&quot;&gt;https://www.freecodecamp.org/news/how-to-set-up-continuous-deployment-to-aws-s3-using-circleci-in-under-30-minutes-a8e268284098/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://medium.com/the-apps-team/deploying-gatsby-site-to-s3-using-circleci-restful-api-9df167158a0&quot;&gt;https://medium.com/the-apps-team/deploying-gatsby-site-to-s3-using-circleci-restful-api-9df167158a0&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Avoiding Webscraping Throttling Using Python and Tor as a Proxy]]></title><description><![CDATA[Edited 2019-07-13 based on concerns Disclaimer I do not condone the use of this information for creating illegal web crawlers. This was more…]]></description><link>https://boredhacking.com/tor-webscraping-proxy/</link><guid isPermaLink="false">https://boredhacking.com/tor-webscraping-proxy/</guid><pubDate>Mon, 08 Jul 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;Edited 2019-07-13 based on concerns&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;I do not condone the use of this information for creating illegal web crawlers. This was more an informational exercise and I wanted to share it with others. Another thing to note is that some sites are able to automatically block IP’s that are Tor exit nodes, so this may not work for some sites that go to these measures.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;The Problem&lt;/h3&gt;
&lt;p&gt;The other day I was starting the search for a new aparment in New York City, which I have done a couple of times now, and was frustrated that StreetEasy doesn’t allow you to filter apartments that are available after a certain date. After a quick search I realized that people have been requesting this feature for &lt;a href=&quot;https://streeteasy.com/talk/discussion/40436-search-listing-available-after-date&quot;&gt;years&lt;/a&gt; (since Oct 2015 to be exact), and it was nowhere in sight and there didn’t seem to be any services out there that did it either. So I had a thought, I used to web scrape sites using Python, why not try it on StreetEasy and filter the apartments myself. Spoiler alert I wasn’t able to do this for a reason I will explain in more detail, but this led me to use a lot of old tools I hadn’t used in a while and come up with a script for scraping through Tor and switching IP’s between requests.&lt;/p&gt;
&lt;h3&gt;The Roadblock&lt;/h3&gt;
&lt;p&gt;So first let me quickly describe the reason I wasn’t able to scrape StreetEasy. At first glance, there appeared to be a few different StreetEasy scraping scripts on Github. However, I thought it was simple enough I’d prefer to do it myself. It had been a while since I had scraped sites and I wanted to do it all (mostly) on my own. However, the first task in my iterative approach was to just get a listing page for a StreetEasy search. This quickly led me to receive the following html&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;body&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value css language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;font-family&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;Arial&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;FreeSans&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;sans-serif&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;table&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;cellpadding&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;cellspacing&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value css language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;margin-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;margin-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tbody&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;td&lt;/span&gt; &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value css language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12px 2%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;table&lt;/span&gt;
            &lt;span class=&quot;token attr-name&quot;&gt;cellpadding&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token attr-name&quot;&gt;cellspacing&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value css language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 96%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tbody&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;td&lt;/span&gt; &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value css language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12px 2%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
                      &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://streeteasy-public.s3.amazonaws.com/StreetEasy_logo_blue.png&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
                      &lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;450px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
                    &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;br&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;br&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
                  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt; &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value css language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;margin-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Pardon Our Interruption&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                      As you were browsing, something about your browser made us
                      think you were a bot. There are a few reasons why this
                      might happen:
                    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                        You&apos;re a power user moving through this website with
                        super-human speed
                      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;You&apos;ve disabled JavaScript in your web browser&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                        A third-party browser plugin, such as Ghostery or
                        NoScript, is preventing JavaScript from running.
                        Additional information is available in this
                        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;/span&gt;
                          &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://ds.tl/help-third-party-plugins&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
                          &lt;span class=&quot;token attr-name&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;_blank&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
                          &lt;span class=&quot;token attr-name&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Third party browser plugins that block javascript&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
                          &lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;support article.&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;a&lt;/span&gt;
                        &lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                      After completing the CAPTCHA below, you will immediately
                      regain access to the site.
                    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
                &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tbody&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;table&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tbody&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;table&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;My initial thought was since I was using the &lt;code class=&quot;language-text&quot;&gt;requests&lt;/code&gt; library that I wasn’t rendering JavaScript so after doing some googling I came across two ways to render JavaScript in Python. I could use the new &lt;code class=&quot;language-text&quot;&gt;requests-html&lt;/code&gt; library or I could use &lt;code class=&quot;language-text&quot;&gt;selenium&lt;/code&gt;. However, I quickly realized neither was able to give me the result I wanted, I was still getting the same html page that said “Pardon Our Interruption”. So now I decided to take a closer look at the scraping scripts I saw on [Github])(&lt;a href=&quot;https://github.com/purcelba/streeteasy_scrape&quot;&gt;https://github.com/purcelba/streeteasy_scrape&lt;/a&gt;) earlier. A few of them had warnings about how their scripts no longer worked because StreetEasy started using &lt;a href=&quot;https://www.distilnetworks.com/&quot;&gt;Distil Networks&lt;/a&gt; to protect them from unwanted bots and web scrapers. After a couple of google searches, I quickly realized I wasn’t going to break through Distil Networks checks very easily and decided to table the web scraping of StreetEasy. Nevertheless, I had come back to web scraping after years and was interested in what I could do with it.&lt;/p&gt;
&lt;h3&gt;The Final Result&lt;/h3&gt;
&lt;p&gt;When I initially thought I was going to web scrape StreetEasy, I wanted a way to do it without getting throttled because I knew I was going to have to go to a lot of individual listing pages to get information. I originally thought this was going to be the biggest problem for me to overcome so I put some thought into it. While in college, I had done some research on &lt;a href=&quot;https://www.torproject.org/&quot;&gt;Tor&lt;/a&gt; and the dark web under &lt;a href=&quot;http://www.soumyabasu.com/&quot;&gt;Soumya Basu&lt;/a&gt;. A brief synopsis of Tor without getting into two much detail is that it’s an onion router. Tor itself stands for The Onion Router (big surprise I know). What Tor does is it routes your traffic through multiple nodes(computers/servers) in a circuit, and then when your HTTP request reaches your end server it looks like it came from the last node in the Tor circuit. Generally there are three hops in the circuit, and it will send your request to a node then that node only knows where to send the message to next until you reach your final destination like google.com. How it does that is by encrypting your request in multiple layers, and at each node a layer is decrypted so it knows where to send the request next until we reach the last(exit) node and the entire message is decrypted and it knows what request you are looking to make. Then the traffic is rerouted back through all the nodes in a similar way until it reaches you. The reason it’s called an onion router is because of the decryption and peeling away of the message at each node (like an onion).&lt;/p&gt;
&lt;p&gt;Through my research I had become acquainted with the &lt;a href=&quot;https://stem.torproject.org/&quot;&gt;Stem&lt;/a&gt; Python package that would allow you to interact with Tor in Python. I knew you could use Tor as a proxy and route your HTTP requests through it in Python, so I thought this could be a good solution to the throttling problem. I imagined the throttling would be IP based, so I could use Tor and change my exit node between requests so that my web scraper wasn’t throttled. However, this ended not being the biggest problem I had sadly.&lt;/p&gt;
&lt;p&gt;Still, I wanted to give it a go because I thought it could be an interesting application in theory. So the general idea behind it was as follows&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Run Tor on your computer&lt;/li&gt;
&lt;li&gt;Use Tor as a proxy for selenium in Python&lt;/li&gt;
&lt;li&gt;Make a request to a website&lt;/li&gt;
&lt;li&gt;Request a new end node/circuit from Tor&lt;/li&gt;
&lt;li&gt;Repeat steps 3 and 4 until all your requests are made&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The code for this is as follows (I saved this as a file called scrape.py and ran it as &lt;code class=&quot;language-text&quot;&gt;python scrape.py&lt;/code&gt;). This was developed using python 3.7.2 (I use &lt;a href=&quot;https://www.anaconda.com/&quot;&gt;Anaconda&lt;/a&gt; and conda for Python version management)&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;python&quot;&gt;&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; stem &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Signal
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; stem&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;control &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Controller
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; selenium &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; webdriver
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; selenium&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;webdriver&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;firefox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;options &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Options
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; bs4 &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; BeautifulSoup

&lt;span class=&quot;token comment&quot;&gt;# signal TOR for a new connection&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;switchIP&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; Controller&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;from_port&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;port &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;9051&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; controller&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        controller&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;authenticate&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        controller&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;signal&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Signal&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;NEWNYM&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# get a new selenium webdriver with tor as the proxy&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;my_proxy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;PROXY_HOST&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;PROXY_PORT&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    fp &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; webdriver&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;FirefoxProfile&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5&lt;/span&gt;
    fp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;set_preference&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;network.proxy.type&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    fp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;set_preference&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;network.proxy.socks&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;PROXY_HOST&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    fp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;set_preference&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;network.proxy.socks_port&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;PROXY_PORT&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    fp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;update_preferences&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    options &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Options&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    options&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;headless &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; webdriver&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Firefox&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;options&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;options&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; firefox_profile&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;fp&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; x &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    proxy &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; my_proxy&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;9050&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    proxy&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;get&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;https://whatsmyip.com/&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    html &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; proxy&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;page_source
    soup &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; BeautifulSoup&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;html&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;lxml&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;soup&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;find&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;span&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;ipv4&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;soup&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;find&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;span&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;ipv6&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    switchIP&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Before starting there are some requirements&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install Tor on your computer, for macs this can be accomplished using homebrew &lt;code class=&quot;language-text&quot;&gt;brew install tor&lt;/code&gt;. You can then run it constantly in the background using the command &lt;code class=&quot;language-text&quot;&gt;brew services start tor&lt;/code&gt; or run it manually using the command &lt;code class=&quot;language-text&quot;&gt;tor&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Make sure you have firefox installed on your computer, this will be required if you want to use the same selenium code above. You can use other browsers but the &lt;code class=&quot;language-text&quot;&gt;my_proxy&lt;/code&gt; method will need to change slightly&lt;/li&gt;
&lt;li&gt;Install selenium, stem, and beautiful soup Python libraries using the command &lt;code class=&quot;language-text&quot;&gt;pip install selenium stem bs4&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;You will also need to update your &lt;code class=&quot;language-text&quot;&gt;torrc&lt;/code&gt; and restart Tor so that you can make requests to the Tor controller. On a mac you can find your &lt;code class=&quot;language-text&quot;&gt;torrc&lt;/code&gt; file at &lt;code class=&quot;language-text&quot;&gt;/usr/local/etc/tor/torrc.sample&lt;/code&gt;. Rename it to &lt;code class=&quot;language-text&quot;&gt;torrc&lt;/code&gt; by doing &lt;code class=&quot;language-text&quot;&gt;mv /usr/local/etc/tor/torrc.sample /usr/local/etc/tor/torrc&lt;/code&gt; and then uncomment the following lines (I will copy the full torrc at the bottom of this post)&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;ControlPort 9051
CookieAuthentication 1&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now let’s talk about the code a little&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;python&quot;&gt;&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# signal TOR for a new connection&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;switchIP&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; Controller&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;from_port&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;port &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;9051&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; controller&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        controller&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;authenticate&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        controller&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;signal&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Signal&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;NEWNYM&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This method is what allows us to switch our IP. It issues a signal (&lt;code class=&quot;language-text&quot;&gt;Signal.NEWNYM&lt;/code&gt;) to the Tor Controller Port, which tells Tor that we want a new circuit for traffic to be routed through. This will give us a new exit node which means our traffic looks like it’s coming from a different IP.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;python&quot;&gt;&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# get a new selenium webdriver with tor as the proxy&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;my_proxy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;PROXY_HOST&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; PROXY_PORT&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    fp &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; webdriver&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;FirefoxProfile&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5&lt;/span&gt;
    fp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;set_preference&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;network.proxy.type&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    fp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;set_preference&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;network.proxy.socks&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;PROXY_HOST&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    fp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;set_preference&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;network.proxy.socks_port&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;PROXY_PORT&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    fp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;update_preferences&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    options &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Options&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    options&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;headless &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; webdriver&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Firefox&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;options&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;options&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; firefox_profile&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;fp&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This method sets up our selenium webdriver to use the Firefox browser in headless mode and to use Tor as a proxy to route our traffic through. This ensures that all of our requests to our selenium webdriver go through Tor and look like they are coming from our exit node.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;python&quot;&gt;&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; x &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    proxy &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; my_proxy&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;9050&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    proxy&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;get&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;https://whatsmyip.com/&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    html &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; proxy&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;page_source
    soup &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; BeautifulSoup&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;html&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;lxml&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;soup&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;find&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;span&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;ipv4&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;soup&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;find&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;span&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;ipv6&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    switchIP&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This last bit of code just sends a request to &lt;a href=&quot;https://whatsmyip.com/&quot;&gt;https://whatsmyip.com/&lt;/a&gt; so that we can check the IP of our request through our selenium webdriver. We print out the ipv4 and ipv6 addresses of the exit node of our Tor circuit because sometimes it’s ipv4 and sometimes it’s ipv6. Then after that we request a new IP by requesting a new Tor circuit to be built. If everything goes well you should get a result in your terminal that looks something like&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;2a0b:f4c1::7&amp;lt;/span&gt;
None
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;Your IPv4: Not Detected&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv6&quot;&gt;2620:7:6001::ffff:c759:e64c&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;2001:67c:2608::1&amp;lt;/span&gt;
None
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;2a0b:f4c1::7&amp;lt;/span&gt;
None
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;Your IPv4: Not Detected&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv6&quot;&gt;2a03:e600:100::15&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;Your IPv4: Not Detected&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv6&quot;&gt;2001:620:20d0::24&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;Your IPv4: Not Detected&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv6&quot;&gt;2a00:1768:1001:21::32a3:201a&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;Your IPv4: Not Detected&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv6&quot;&gt;2a03:e600:100::19&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;Your IPv4: Not Detected&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv6&quot;&gt;2a03:e600:100::1c&amp;lt;/span&gt;
&amp;lt;span class=&quot;pull-right&quot; id=&quot;ipv4&quot;&gt;2a0b:f4c1::7&amp;lt;/span&gt;
None&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see my IP address changes between calls, which is exactly what we are looking for. The server we are making the request to thinks that we are the Tor exit node, and each request we made looks like it’s coming from a different computer. The &lt;code class=&quot;language-text&quot;&gt;None&lt;/code&gt; values are because if you have an ipv4 value than it doesn’t show anything for &lt;code class=&quot;language-text&quot;&gt;ipv6&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;And just like that you can hide your real IP when making HTTP requests using Python. I hope this is hepful, and if you have any questions or corrections feel free to leave a comment below!&lt;/p&gt;
&lt;h3&gt;Additional Resources&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://hackernoon.com/web-scraping-tutorial-with-python-tips-and-tricks-db070e70e071&quot;&gt;https://hackernoon.com/web-scraping-tutorial-with-python-tips-and-tricks-db070e70e071&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-python.html&quot;&gt;https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-python.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/30286293/make-requests-using-python-over-tor&quot;&gt;https://stackoverflow.com/questions/30286293/make-requests-using-python-over-tor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.thedurkweb.com/automated-anonymous-interactions-with-websites-using-python-and-tor/&quot;&gt;https://www.thedurkweb.com/automated-anonymous-interactions-with-websites-using-python-and-tor/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://stem.torproject.org/tutorials/examples/exit_used.html&quot;&gt;https://stem.torproject.org/tutorials/examples/exit_used.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/15459170/trouble-authenticating-tor-with-python&quot;&gt;https://stackoverflow.com/questions/15459170/trouble-authenticating-tor-with-python&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Full Torrc&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;## Configuration file for a typical Tor user
## Last updated 22 December 2017 for Tor 0.3.2.8-rc.
## (may or may not work for much older or much newer versions of Tor.)
##
## Lines that begin with &quot;## &quot; try to explain what&apos;s going on. Lines
## that begin with just &quot;#&quot; are disabled commands: you can enable them
## by removing the &quot;#&quot; symbol.
##
## See &apos;man tor&apos;, or https://www.torproject.org/docs/tor-manual.html,
## for more options you can use in this file.
##
## Tor will look for this file in various places based on your platform:
## https://www.torproject.org/docs/faq#torrc

## Tor opens a SOCKS proxy on port 9050 by default -- even if you don&apos;t
## configure one below. Set &quot;SOCKSPort 0&quot; if you plan to run Tor only
## as a relay, and not make any local application connections yourself.
#SOCKSPort 9050 # Default: Bind to localhost:9050 for local connections.
#SOCKSPort 192.168.0.1:9100 # Bind to this address:port too.

## Entry policies to allow/deny SOCKS requests based on IP address.
## First entry that matches wins. If no SOCKSPolicy is set, we accept
## all (and only) requests that reach a SOCKSPort. Untrusted users who
## can access your SOCKSPort may be able to learn about the connections
## you make.
#SOCKSPolicy accept 192.168.0.0/16
#SOCKSPolicy accept6 FC00::/7
#SOCKSPolicy reject *

## Logs go to stdout at level &quot;notice&quot; unless redirected by something
## else, like one of the below lines. You can have as many Log lines as
## you want.
##
## We advise using &quot;notice&quot; in most cases, since anything more verbose
## may provide sensitive information to an attacker who obtains the logs.
##
## Send all messages of level &apos;notice&apos; or higher to /usr/local/var/log/tor/notices.log
#Log notice file /usr/local/var/log/tor/notices.log
## Send every possible message to /usr/local/var/log/tor/debug.log
#Log debug file /usr/local/var/log/tor/debug.log
## Use the system log instead of Tor&apos;s logfiles
#Log notice syslog
## To send all messages to stderr:
#Log debug stderr

## Uncomment this to start the process in the background... or use
## --runasdaemon 1 on the command line. This is ignored on Windows;
## see the FAQ entry if you want Tor to run as an NT service.
#RunAsDaemon 1

## The directory for keeping all the keys/etc. By default, we store
## things in $HOME/.tor on Unix, and in Application Data\tor on Windows.
#DataDirectory /usr/local/var/lib/tor

## The port on which Tor will listen for local connections from Tor
## controller applications, as documented in control-spec.txt.
ControlPort 9051
## If you enable the controlport, be sure to enable one of these
## authentication methods, to prevent attackers from accessing it.
#HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C
CookieAuthentication 1

############### This section is just for location-hidden services ###

## Once you have configured a hidden service, you can look at the
## contents of the file &quot;.../hidden_service/hostname&quot; for the address
## to tell people.
##
## HiddenServicePort x y:z says to redirect requests on port x to the
## address y:z.

#HiddenServiceDir /usr/local/var/lib/tor/hidden_service/
#HiddenServicePort 80 127.0.0.1:80

#HiddenServiceDir /usr/local/var/lib/tor/other_hidden_service/
#HiddenServicePort 80 127.0.0.1:80
#HiddenServicePort 22 127.0.0.1:22

################ This section is just for relays #####################
#
## See https://www.torproject.org/docs/tor-doc-relay for details.

## Required: what port to advertise for incoming Tor connections.
#ORPort 9001
## If you want to listen on a port other than the one advertised in
## ORPort (e.g. to advertise 443 but bind to 9090), you can do it as
## follows.  You&apos;ll need to do ipchains or other port forwarding
## yourself to make this work.
#ORPort 443 NoListen
#ORPort 127.0.0.1:9090 NoAdvertise

## The IP address or full DNS name for incoming connections to your
## relay. Leave commented out and Tor will guess.
#Address noname.example.com

## If you have multiple network interfaces, you can specify one for
## outgoing traffic to use.
## OutboundBindAddressExit will be used for all exit traffic, while
## OutboundBindAddressOR will be used for all OR and Dir connections
## (DNS connections ignore OutboundBindAddress).
## If you do not wish to differentiate, use OutboundBindAddress to
## specify the same address for both in a single line.
#OutboundBindAddressExit 10.0.0.4
#OutboundBindAddressOR 10.0.0.5

## A handle for your relay, so people don&apos;t have to refer to it by key.
## Nicknames must be between 1 and 19 characters inclusive, and must
## contain only the characters [a-zA-Z0-9].
## If not set, &quot;Unnamed&quot; will be used.
#Nickname ididnteditheconfig

## Define these to limit how much relayed traffic you will allow. Your
## own traffic is still unthrottled. Note that RelayBandwidthRate must
## be at least 75 kilobytes per second.
## Note that units for these config options are bytes (per second), not
## bits (per second), and that prefixes are binary prefixes, i.e. 2^10,
## 2^20, etc.
#RelayBandwidthRate 100 KBytes  # Throttle traffic to 100KB/s (800Kbps)
#RelayBandwidthBurst 200 KBytes # But allow bursts up to 200KB (1600Kb)

## Use these to restrict the maximum traffic per day, week, or month.
## Note that this threshold applies separately to sent and received bytes,
## not to their sum: setting &quot;40 GB&quot; may allow up to 80 GB total before
## hibernating.
##
## Set a maximum of 40 gigabytes each way per period.
#AccountingMax 40 GBytes
## Each period starts daily at midnight (AccountingMax is per day)
#AccountingStart day 00:00
## Each period starts on the 3rd of the month at 15:00 (AccountingMax
## is per month)
#AccountingStart month 3 15:00

## Administrative contact information for this relay or bridge. This line
## can be used to contact you if your relay or bridge is misconfigured or
## something else goes wrong. Note that we archive and publish all
## descriptors containing these lines and that Google indexes them, so
## spammers might also collect them. You may want to obscure the fact that
## it&apos;s an email address and/or generate a new address for this purpose.
##
## If you are running multiple relays, you MUST set this option.
##
#ContactInfo Random Person &amp;lt;nobody AT example dot com&gt;
## You might also include your PGP or GPG fingerprint if you have one:
#ContactInfo 0xFFFFFFFF Random Person &amp;lt;nobody AT example dot com&gt;

## Uncomment this to mirror directory information for others. Please do
## if you have enough bandwidth.
#DirPort 9030 # what port to advertise for directory connections
## If you want to listen on a port other than the one advertised in
## DirPort (e.g. to advertise 80 but bind to 9091), you can do it as
## follows.  below too. You&apos;ll need to do ipchains or other port
## forwarding yourself to make this work.
#DirPort 80 NoListen
#DirPort 127.0.0.1:9091 NoAdvertise
## Uncomment to return an arbitrary blob of html on your DirPort. Now you
## can explain what Tor is if anybody wonders why your IP address is
## contacting them. See contrib/tor-exit-notice.html in Tor&apos;s source
## distribution for a sample.
#DirPortFrontPage /usr/local/etc/tor/tor-exit-notice.html

## Uncomment this if you run more than one Tor relay, and add the identity
## key fingerprint of each Tor relay you control, even if they&apos;re on
## different networks. You declare it here so Tor clients can avoid
## using more than one of your relays in a single circuit. See
## https://www.torproject.org/docs/faq#MultipleRelays
## However, you should never include a bridge&apos;s fingerprint here, as it would
## break its concealability and potentially reveal its IP/TCP address.
##
## If you are running multiple relays, you MUST set this option.
##
## Note: do not use MyFamily on bridge relays.
#MyFamily $keyid,$keyid,...

## Uncomment this if you do *not* want your relay to allow any exit traffic.
## (Relays allow exit traffic by default.)
#ExitRelay 0

## Uncomment this if you want your relay to allow IPv6 exit traffic.
## (Relays only allow IPv4 exit traffic by default.)
#IPv6Exit 1

## A comma-separated list of exit policies. They&apos;re considered first
## to last, and the first match wins.
##
## If you want to allow the same ports on IPv4 and IPv6, write your rules
## using accept/reject *. If you want to allow different ports on IPv4 and
## IPv6, write your IPv6 rules using accept6/reject6 *6, and your IPv4 rules
## using accept/reject *4.
##
## If you want to _replace_ the default exit policy, end this with either a
## reject *:* or an accept *:*. Otherwise, you&apos;re _augmenting_ (prepending to)
## the default exit policy. Leave commented to just use the default, which is
## described in the man page or at
## https://www.torproject.org/documentation.html
##
## Look at https://www.torproject.org/faq-abuse.html#TypicalAbuses
## for issues you might encounter if you use the default exit policy.
##
## If certain IPs and ports are blocked externally, e.g. by your firewall,
## you should update your exit policy to reflect this -- otherwise Tor
## users will be told that those destinations are down.
##
## For security, by default Tor rejects connections to private (local)
## networks, including to the configured primary public IPv4 and IPv6 addresses,
## and any public IPv4 and IPv6 addresses on any interface on the relay.
## See the man page entry for ExitPolicyRejectPrivate if you want to allow
## &quot;exit enclaving&quot;.
##
#ExitPolicy accept *:6660-6667,reject *:* # allow irc ports on IPv4 and IPv6 but no more
#ExitPolicy accept *:119 # accept nntp ports on IPv4 and IPv6 as well as default exit policy
#ExitPolicy accept *4:119 # accept nntp ports on IPv4 only as well as default exit policy
#ExitPolicy accept6 *6:119 # accept nntp ports on IPv6 only as well as default exit policy
#ExitPolicy reject *:* # no exits allowed

## Bridge relays (or &quot;bridges&quot;) are Tor relays that aren&apos;t listed in the
## main directory. Since there is no complete public list of them, even an
## ISP that filters connections to all the known Tor relays probably
## won&apos;t be able to block all the bridges. Also, websites won&apos;t treat you
## differently because they won&apos;t know you&apos;re running Tor. If you can
## be a real relay, please do; but if not, be a bridge!
##
## Warning: when running your Tor as a bridge, make sure than MyFamily is
## NOT configured.
#BridgeRelay 1
## By default, Tor will advertise your bridge to users through various
## mechanisms like https://bridges.torproject.org/. If you want to run
## a private bridge, for example because you&apos;ll give out your bridge
## address manually to your friends, uncomment this line:
#PublishServerDescriptor 0

## Configuration options can be imported from files or folders using the %include
## option with the value being a path. If the path is a file, the options from the
## file will be parsed as if they were written where the %include option is. If
## the path is a folder, all files on that folder will be parsed following lexical
## order. Files starting with a dot are ignored. Files on subfolders are ignored.
## The %include option can be used recursively.
#%include /etc/torrc.d/
#%include /etc/torrc.custom&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Deploying a New Docker Image to an EKS Cluster on Codeship]]></title><description><![CDATA[In two of my previous posts we created a Docker image for a Next.js application and pushed it to ECR, and then we also talked about setting…]]></description><link>https://boredhacking.com/deploying-to-eks-codeship/</link><guid isPermaLink="false">https://boredhacking.com/deploying-to-eks-codeship/</guid><pubDate>Sun, 19 May 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In two of my previous posts we &lt;a href=&quot;/next-js-docker-ecr&quot;&gt;created a Docker image for a Next.js application and pushed it to ECR&lt;/a&gt;, and then we also talked about &lt;a href=&quot;/setup-deployment-on-eks&quot;&gt;setting up and deploying an application to EKS&lt;/a&gt;. This post details how to setup auto deployments to EKS on Codeship for your application’s Docker images. We ran into quite a few problems trying to follow Codeship’s documentation, so hopefully this post can help some other’s get through the issues we encountered.&lt;/p&gt;
&lt;h3&gt;Codeship Pro vs Codeship Basic&lt;/h3&gt;
&lt;p&gt;The first thing to note is that all the examples on Codeship are done using Codeship Pro, which is their newer offering. We have been using Codeship for a few years now and have all of our projects using Codeship Basic. Although it is possible to use Codeship Basic to deploy to EKS, it’s much easier to use Codeship Pro because Codeship has created Docker containers to help you. So we started our new project with Codeship Pro and this tutorial will be done using Codeship Pro. In order to use Codeship Pro you must define a “codeship-services.yml” and a “codeship-steps.yml”. These files tell Codeship how to setup your project and how you want to test and deploy it. I will go over how we setup both of these files to test our application, push an updated image to ECR, and deploye the updated image to EKS.&lt;/p&gt;
&lt;h3&gt;Codeship Services&lt;/h3&gt;
&lt;p&gt;Let’s start by showing you our “codeship-services.yml”, and then we can go over what each section of this file is doing.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;app-staging&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
    &lt;span class=&quot;token key atrule&quot;&gt;dockerfile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Dockerfile.staging
  &lt;span class=&quot;token key atrule&quot;&gt;volumes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; .&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;/code

&lt;span class=&quot;token key atrule&quot;&gt;app-production&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 146222393540.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production
    &lt;span class=&quot;token key atrule&quot;&gt;dockerfile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Dockerfile.production
  &lt;span class=&quot;token key atrule&quot;&gt;volumes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; .&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;/code

&lt;span class=&quot;token key atrule&quot;&gt;app-test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; company_name/app
    &lt;span class=&quot;token key atrule&quot;&gt;dockerfile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Dockerfile.codeship

&lt;span class=&quot;token key atrule&quot;&gt;aws-generator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; codeship/aws&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;ecr&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;dockercfg&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;generator
  &lt;span class=&quot;token key atrule&quot;&gt;encrypted_env_file&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws_creds_k8s_env.encrypted &lt;span class=&quot;token comment&quot;&gt;# contains Secret, AccessKey, Region, and k8s config&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;add_docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean important&quot;&gt;true&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;kubernetes-deployment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;encrypted_env_file&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws_creds_k8s_env.encrypted
  &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; codeship/eks&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;kubectl&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;Creating our App’s Docker Container&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;app-staging&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.AWS_REGION.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
    &lt;span class=&quot;token key atrule&quot;&gt;dockerfile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Dockerfile.staging
  &lt;span class=&quot;token key atrule&quot;&gt;volumes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; .&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;/code

&lt;span class=&quot;token key atrule&quot;&gt;app-production&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 146222393540.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production
    &lt;span class=&quot;token key atrule&quot;&gt;dockerfile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Dockerfile.production
  &lt;span class=&quot;token key atrule&quot;&gt;volumes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; .&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;/code&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first part of this file creates our staging and production app services which create a Docker images. These will be the images that we push to ECR and then deploy to EKS. Since they are essentially the same we will only go over the staging application. We must specify the image name and the dockerfile to use to build the image. The &lt;strong&gt;volumes&lt;/strong&gt; value allows us to define where our applications code will reside, which in this case is within the /code directory.&lt;/p&gt;
&lt;h4&gt;Creating our App’s Test Service&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;app-test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; company_name/app
    &lt;span class=&quot;token key atrule&quot;&gt;dockerfile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Dockerfile.codeship&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is similar to our &lt;strong&gt;app&lt;/strong&gt; service. Here we are defining a Docker container for us to run our tests in, but as you can see the Dockerfile we are using is different. This is because we can simplify our container so that it doesn’t necessarily need to run the application our build it. We just need our applications files in the container so that we can run our test commands.&lt;/p&gt;
&lt;h4&gt;Creating the aws-generator Service&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;aws-generator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; codeship/aws&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;ecr&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;dockercfg&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;generator
  &lt;span class=&quot;token key atrule&quot;&gt;encrypted_env_file&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws_creds_k8s_env.encrypted &lt;span class=&quot;token comment&quot;&gt;# contains Secret, AccessKey, Region, and k8s config&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; AWS_REGION=us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;add_docker&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean important&quot;&gt;true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;strong&gt;aws-generator&lt;/strong&gt; service is how we are going to push our new Docker image to ECR and tag it. We use the &lt;strong&gt;codeship/aws-ecr-dockercfg-generator&lt;/strong&gt; Docker image which has functionality to push to ECR built into it. We pass an &lt;strong&gt;encrypted_env_file&lt;/strong&gt; value of &lt;strong&gt;aws_creds_k8s_env.encrypted&lt;/strong&gt; which is a file within our code repository. This file is an encrypted &lt;strong&gt;.env&lt;/strong&gt; file so that we can check it into the repo but includes AWS credentials and our kubeconfig file so we can deploy to EKS. This &lt;strong&gt;.env&lt;/strong&gt; file consists of the following keys&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
AWS_REGION=...
ENV_VAR_HELPER=...&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;strong&gt;AWS_ACCESS_KEY_ID&lt;/strong&gt; and &lt;strong&gt;AWS_SECRET_ACCESS_KEY&lt;/strong&gt; are your AWS access key and secret for an account that has both ECR push access and EKS deploy access. The &lt;strong&gt;AWS_REGION&lt;/strong&gt; is the region that you have your ECR repository and EKS cluster. &lt;strong&gt;ENV_VAR_HELPER&lt;/strong&gt; is a special value that has your kubeconfig stored in it. You must make sure that your kubeconfig stored in this value has both of your clusters (staging and production) in it. We generate this value using a Docker container made by Codeship. This can be done using the following commands.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;kubectl config view &lt;span class=&quot;token parameter variable&quot;&gt;--flatten&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; kubeconfigdata
&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; run &lt;span class=&quot;token parameter variable&quot;&gt;--rm&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-it&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;pwd&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;)&lt;/span&gt;&lt;/span&gt;:/files codeship/env-var-helper &lt;span class=&quot;token function&quot;&gt;cp&lt;/span&gt; kubeconfigdata:/root/.kube/config k8s-env&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first command flattens your kubeconfig and stores it in a file called kubeconfigdata. Then we run a command using the &lt;strong&gt;codeship/env-var-helper&lt;/strong&gt; Docker container. This creates a &lt;strong&gt;k8s-env&lt;/strong&gt; file which will have your &lt;strong&gt;ENV_VAR_HELPER&lt;/strong&gt; value. You can either move this &lt;strong&gt;ENV_VAR_HELPER&lt;/strong&gt; value to another &lt;strong&gt;.env&lt;/strong&gt; file or put your AWS credentials in here.&lt;/p&gt;
&lt;p&gt;In order to create the &lt;strong&gt;aws_creds_k8s_env.encrypted&lt;/strong&gt; file we must download and use the &lt;code class=&quot;language-text&quot;&gt;jet&lt;/code&gt; cli created by Codeship. This cli allows us to run our Codeship Pro builds locally as well as encrypt values. First you must get your aes key from your Codeship Pro project. You can find this in the settings. Copy and paste the value into a file called &lt;strong&gt;codeship.aes&lt;/strong&gt; (you can use another name for the file but you will need to pass that value into the jet command using —key-path). Next you need to download the &lt;code class=&quot;language-text&quot;&gt;jet&lt;/code&gt; cli, which can be done through homebrew on mac using the following command &lt;code class=&quot;language-text&quot;&gt;brew cask install codeship/taps/jet&lt;/code&gt; or you can look &lt;a href=&quot;https://documentation.codeship.com/pro/jet-cli/installation/&quot;&gt;here&lt;/a&gt; to see how to install on other machines. Once it is installed, you can encrypt your &lt;strong&gt;.env&lt;/strong&gt; file by using the following command &lt;code class=&quot;language-text&quot;&gt;jet encrypt .env aws_creds_k8s_env.encrypted&lt;/code&gt;. You can replace &lt;strong&gt;.env&lt;/strong&gt; with whatever you have named your environment file and the same goes for the second command which is the name of the outputted encrypted file.&lt;/p&gt;
&lt;p&gt;The last key in this service is &lt;strong&gt;add_docker&lt;/strong&gt;. The &lt;strong&gt;add_docker&lt;/strong&gt; key tells the service to make sure it adds docker to the container so that we can run docker cli specific commands. These are necessary to build our image and deploy to ECR.&lt;/p&gt;
&lt;h4&gt;Creating the kubernetes-deployment Service&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;kubernetes-deployment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;encrypted_env_file&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws_creds_k8s_env.encrypted
  &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; codeship/eks&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;kubectl&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This last service, &lt;strong&gt;kubernetes-deployment&lt;/strong&gt;, will be how we deploy our updated Docker image to our EKS cluster. We also pass in our encrypted environment file here &lt;code class=&quot;language-text&quot;&gt;encrypted_env_file: aws_creds_k8s_env.encrypted&lt;/code&gt;. We then specify the image which is one created and maintained by codeship, &lt;code class=&quot;language-text&quot;&gt;image: codeship/eks-kubectl&lt;/code&gt;. This will allow us to run &lt;code class=&quot;language-text&quot;&gt;kubectl&lt;/code&gt; commands that modify our EKS cluster.&lt;/p&gt;
&lt;h3&gt;Codeship Steps&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ci
  &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; parallel
  &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;test
      &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; npm test

&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; serial
  &lt;span class=&quot;token key atrule&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; master
  &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
      &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push
      &lt;span class=&quot;token key atrule&quot;&gt;image_tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;{{.CommitID}}&quot;&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
      &lt;span class=&quot;token key atrule&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com
      &lt;span class=&quot;token key atrule&quot;&gt;image_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
      &lt;span class=&quot;token key atrule&quot;&gt;dockercfg_service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;generator
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deploy
      &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; kubernetes&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment
      &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; /bin/sh &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;c &apos;kubectl config use&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;context arn&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;aws&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;eks&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;ACCOUNT_ID&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;cluster/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging &lt;span class=&quot;token important&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; kubectl set image deployment/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging=ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;$CI_COMMIT_ID&apos;

&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; serial
  &lt;span class=&quot;token key atrule&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; production
  &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production
      &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push
      &lt;span class=&quot;token key atrule&quot;&gt;image_tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;{{.CommitID}}&quot;&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production
      &lt;span class=&quot;token key atrule&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com
      &lt;span class=&quot;token key atrule&quot;&gt;image_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production
      &lt;span class=&quot;token key atrule&quot;&gt;dockercfg_service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;generator
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; production&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deploy
      &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; kubernetes&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment
      &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; /bin/sh &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;c &apos;kubectl config use&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;context user@app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.eksctl.io &lt;span class=&quot;token important&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; kubectl set image deployment/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production=ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;$CI_COMMIT_ID&apos;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here is our full &lt;strong&gt;codeship-steps.yml&lt;/strong&gt; file. We will talk about each section in more detail in the following sections, but as you can see it is broken up into two sections. The first section runs our test on every push to a branch on github. The second section handles deploying our application.&lt;/p&gt;
&lt;h4&gt;Testing&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ci
  &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; parallel
  &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;test
      &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; npm test&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This section of the file handles running out tests. We have passed a &lt;strong&gt;type&lt;/strong&gt; of &lt;strong&gt;parallel&lt;/strong&gt; which means the following commands will all be run in parallel. Although we only have one test command, you could define multiples steps here and use &lt;strong&gt;parallel&lt;/strong&gt; to split up your tests and run them in parallel so that you speed up your continuous integration. You must define what service to use, which in our case is &lt;strong&gt;app-test&lt;/strong&gt; (our container we created for testing in the codeship-services.yml). You must also define the command to run which in our case is &lt;code class=&quot;language-text&quot;&gt;npm test&lt;/code&gt; since we are testing a Next.js application. This part of the &lt;strong&gt;codeship-steps.yml&lt;/strong&gt; is run on every push of a branch to our Github repo and allows us to continuously test our application.&lt;/p&gt;
&lt;h4&gt;Deploying&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; serial
  &lt;span class=&quot;token key atrule&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; master
  &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
      &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push
      &lt;span class=&quot;token key atrule&quot;&gt;image_tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;{{.CommitID}}&quot;&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
      &lt;span class=&quot;token key atrule&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com
      &lt;span class=&quot;token key atrule&quot;&gt;image_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
      &lt;span class=&quot;token key atrule&quot;&gt;dockercfg_service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;generator
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deploy
      &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; kubernetes&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment
      &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; /bin/sh &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;c &apos;kubectl config use&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;context arn&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;aws&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;eks&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;ACCOUNT_ID&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;cluster/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging &lt;span class=&quot;token important&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; kubectl set image deployment/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging=ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;$CI_COMMIT_ID&apos;

&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; serial
  &lt;span class=&quot;token key atrule&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; production
  &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production
      &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push
      &lt;span class=&quot;token key atrule&quot;&gt;image_tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;{{.CommitID}}&quot;&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production
      &lt;span class=&quot;token key atrule&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com
      &lt;span class=&quot;token key atrule&quot;&gt;image_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production
      &lt;span class=&quot;token key atrule&quot;&gt;dockercfg_service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;generator
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; production&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deploy
      &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; kubernetes&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment
      &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; /bin/sh &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;c &apos;kubectl config use&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;context user@app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.eksctl.io &lt;span class=&quot;token important&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; kubectl set image deployment/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production=ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;production&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;$CI_COMMIT_ID&apos;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is the meat of our &lt;strong&gt;codeship-steps.yml&lt;/strong&gt; file and handles our deployments. As you can tell there is a separate set of steps for our staging and production deploys. As you can see, these steps have a type of &lt;strong&gt;serial&lt;/strong&gt; because we want to run these steps one by one and only run the next one if the previous one was successful. The next thing to note is the &lt;strong&gt;tag&lt;/strong&gt; value of &lt;strong&gt;master&lt;/strong&gt; or &lt;strong&gt;production&lt;/strong&gt;. This means that we are only going to run this step if we are on the &lt;strong&gt;master&lt;/strong&gt; or &lt;strong&gt;production&lt;/strong&gt; branches of our Github repo. Therefore these steps are skipped on most of our branches. There are two substeps of these steps, one for pushing the new updated Docker image to ECR and one to deploy to EKS. We will only go over the staging steps since they are the same as the production steps.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; push
  &lt;span class=&quot;token key atrule&quot;&gt;image_tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;{{.CommitID}}&quot;&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com
  &lt;span class=&quot;token key atrule&quot;&gt;image_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;dockercfg_service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;generator&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;strong&gt;name&lt;/strong&gt; value can be anything you want it to be but we defined it as &lt;strong&gt;push&lt;/strong&gt; since we are pushing to ECR. The &lt;strong&gt;type&lt;/strong&gt; is also &lt;strong&gt;push&lt;/strong&gt; since it is a push to ECR. The &lt;strong&gt;image_tag&lt;/strong&gt; is what you want to tag your Docker image as when you push it to ECR. We use the commit sha so we can match a Docker image in ECR to a given commit in our git log. We are using the Go string template since that is how Codeship allows you to do this, and they give us access to the commit sha through the &lt;strong&gt;CommitId&lt;/strong&gt; value. The &lt;strong&gt;service&lt;/strong&gt; is which service in your &lt;strong&gt;codeship-services.yml&lt;/strong&gt; you want to use. The &lt;strong&gt;registry&lt;/strong&gt; value is what Docker image registry you are using. There are many different registries and you can use different ones. However, you may need to use a different Docker image for your &lt;strong&gt;dockercfg_service&lt;/strong&gt; since we are using &lt;strong&gt;codeship/aws-ecr-dockercfg-generator&lt;/strong&gt; which is ECR specific. The &lt;strong&gt;image_name&lt;/strong&gt; is which repository in your registry to use. And finally, the &lt;strong&gt;dockercfg_service&lt;/strong&gt; is the service from your &lt;strong&gt;codeship-services.yml&lt;/strong&gt; that will know how to deploy to ECR.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deploy
  &lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; kubernetes&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment
  &lt;span class=&quot;token key atrule&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; /bin/sh &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;c &apos;kubectl config use&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;context arn&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;aws&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;eks&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;ACCOUNT_ID&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;cluster/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging &lt;span class=&quot;token important&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; kubectl set image deployment/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging=ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;$CI_COMMIT_ID&apos;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The last step is how we deploy changes to EKS. The &lt;strong&gt;service&lt;/strong&gt; we are using is our &lt;strong&gt;kubernetes-deployment&lt;/strong&gt; service which we defined in our &lt;strong&gt;codeship-services.yml&lt;/strong&gt;. We then pass the &lt;strong&gt;command&lt;/strong&gt; we want to run in the container to deploy to EKS. We run it with &lt;code class=&quot;language-text&quot;&gt;/bin/sh -c &apos;...&apos;&lt;/code&gt; so that we can pass it an environment value which in this case is &lt;strong&gt;CI_COMMIT_ID&lt;/strong&gt;. This environment value is our commit’s sha, which is what we used in the last step to tag our new image in ECR, and is necessary to deploy the right image to our EKS worker nodes. We then run two kubectl commands, &lt;code class=&quot;language-text&quot;&gt;kubectl config use-context arn:aws:eks:us-east-1:ACCOUNT_ID:cluster/app-staging&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;kubectl set image deployment/app-deployment thor-staging=ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/app:$CI_COMMIT_ID&lt;/code&gt; The first makes sure we use the right context for our cluster since our kubeconfig (which we stored in our encryped env file) has multiple clusters in it, staging and production. The second command set’s our new Docker image on our EKS deployment that we defined in our initial deployment and is name &lt;strong&gt;deployment/app-staging-deployment&lt;/strong&gt;. Now with that we have successfully pushed our new Docker image to ECR and deployed it to EKS.&lt;/p&gt;
&lt;h3&gt;Using the Jet Cli&lt;/h3&gt;
&lt;p&gt;One cool thing that we haven’t discussed yet in detail, is the ability to test your Codeship Pro build locally using the &lt;code class=&quot;language-text&quot;&gt;jet&lt;/code&gt; cli. You can do this by running the &lt;code class=&quot;language-text&quot;&gt;jet steps&lt;/code&gt; command to run your &lt;strong&gt;codeship-steps.yml&lt;/strong&gt; file. This is a great tool for debugging locally before deploying. There are a few things to note for our &lt;strong&gt;codeship-steps.yml&lt;/strong&gt; though. The first is that if you want to test your deploy steps you must pass the branch that triggers your deploy using the &lt;code class=&quot;language-text&quot;&gt;--tag&lt;/code&gt; flag. If you don’t want your deploy to skip your &lt;strong&gt;push&lt;/strong&gt; step to ECR or another container registry you need to pass the &lt;code class=&quot;language-text&quot;&gt;--push&lt;/code&gt; flag. And lastly, because we use the &lt;strong&gt;CI_COMMIT_ID&lt;/strong&gt; environment variable you have to set this using the &lt;code class=&quot;language-text&quot;&gt;--ci-commit-id&lt;/code&gt; flag or else your test deploy will not have this value set, which will cause the push to error out. Altogether to test your full steps file you should run a command similar to this one &lt;code class=&quot;language-text&quot;&gt;jet steps --tag master --push --ci-commit-id 4981234&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;Additional Resources&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://blog.codeship.com/using-aws-eks-in-your-continuous-integration-workflow/&quot;&gt;https://blog.codeship.com/using-aws-eks-in-your-continuous-integration-workflow/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://documentation.codeship.com/pro/continuous-deployment/aws-eks/#deploying-to-eks&quot;&gt;https://documentation.codeship.com/pro/continuous-deployment/aws-eks/#deploying-to-eks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://documentation.codeship.com/pro/continuous-deployment/deployment-with-kubernetes/&quot;&gt;https://documentation.codeship.com/pro/continuous-deployment/deployment-with-kubernetes/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://documentation.codeship.com/pro/builds-and-configuration/steps/&quot;&gt;https://documentation.codeship.com/pro/builds-and-configuration/steps/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://blog.codeship.com/aws-registry/&quot;&gt;https://blog.codeship.com/aws-registry/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://documentation.codeship.com/pro/builds-and-configuration/environment-variables/&quot;&gt;https://documentation.codeship.com/pro/builds-and-configuration/environment-variables/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://documentation.codeship.com/pro/jet-cli/installation/&quot;&gt;https://documentation.codeship.com/pro/jet-cli/installation/&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Setting Up AWS Elastic Kubernetes Service (EKS) and Deploying]]></title><description><![CDATA[In a previous post I talked about setting up a Next.js Docker container and deploying it to Elastic Container Registry (ECR). This was the…]]></description><link>https://boredhacking.com/setup-and-deployment-on-eks/</link><guid isPermaLink="false">https://boredhacking.com/setup-and-deployment-on-eks/</guid><pubDate>Wed, 15 May 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In a previous &lt;a href=&quot;/next-js-docker-ecr&quot;&gt;post&lt;/a&gt; I talked about setting up a Next.js Docker container and deploying it to Elastic Container Registry (ECR). This was the first step for us to get our Next.js app ready to deploy to Elastic Kubernetes Service (EKS), but you could use any other Docker image with this tutorial to deploy to EKS.&lt;/p&gt;
&lt;p&gt;The first part of this tutorial will follow along with AWS’s tutorial on setting up EKS using their management console which you can find &lt;a href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/getting-started-console.html&quot;&gt;here&lt;/a&gt;. Since we’ve deployed our EKS cluster, a cli has been released called &lt;code class=&quot;language-text&quot;&gt;eksctl&lt;/code&gt; which can be used for creating and managing EKS clusters. Amazon has a second tutorial &lt;a href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html&quot;&gt;here&lt;/a&gt; describing setup and deployment of an EKS cluster using &lt;code class=&quot;language-text&quot;&gt;eksctl&lt;/code&gt;. I will go over how to setup your EKS cluster using &lt;code class=&quot;language-text&quot;&gt;eksctl&lt;/code&gt; after first going over using the management console. I highly recommend at least reading the management console tutorial first so you can understand what &lt;code class=&quot;language-text&quot;&gt;eksctl&lt;/code&gt; does under the hood.&lt;/p&gt;
&lt;h3&gt;Deploying an EKS cluster using the AWS management console&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Create an EKS Service role in IAM management console&lt;/li&gt;
&lt;li&gt;Setup your VPC in Cloudformation’s management console using the supplied template YAML file in the tutorial&lt;/li&gt;
&lt;li&gt;Install &lt;code class=&quot;language-text&quot;&gt;kubectl&lt;/code&gt; for Amazon EKS&lt;/li&gt;
&lt;li&gt;Install &lt;code class=&quot;language-text&quot;&gt;aws-iam-authenticator&lt;/code&gt; for Amazon EKS&lt;/li&gt;
&lt;li&gt;Install the &lt;code class=&quot;language-text&quot;&gt;aws-cli&lt;/code&gt; using &lt;code class=&quot;language-text&quot;&gt;pip&lt;/code&gt; (recommend using a newer version of python, 3.6 or above)&lt;/li&gt;
&lt;li&gt;Create the EKS cluster in the management console&lt;/li&gt;
&lt;li&gt;Create a kubeconfig file for the cluster&lt;/li&gt;
&lt;li&gt;Launch and configure EKS worker nodes using Cloudformation and the template YAML file AWS gives you, in the management console&lt;/li&gt;
&lt;li&gt;Allow the EKS worker nodes to join the EKS cluster, by using &lt;code class=&quot;language-text&quot;&gt;kubectl&lt;/code&gt; and an authentication YAML file the tutorial shows you how to create&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Deploying an EKS cluster using ekstl&lt;/h3&gt;
&lt;p&gt;First make sure you have downloaded the &lt;code class=&quot;language-text&quot;&gt;aws-cli&lt;/code&gt; tool and configured your account information.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;$ pip &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; awscli &lt;span class=&quot;token parameter variable&quot;&gt;--upgrade&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--user&lt;/span&gt;
$ aws configure
AWS Access Key ID &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;None&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;None&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;None&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;: us-east-1
Default output &lt;span class=&quot;token function&quot;&gt;format&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;None&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;: json&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next you need to install &lt;code class=&quot;language-text&quot;&gt;eksctl&lt;/code&gt; which if you have a mac can be done through homebrew. If you do not have a mac you can look at the tutorial linked below to find out how to do this.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;brew tap weaveworks/tap
brew &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; weaveworks/tap/eksctl&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Check your &lt;code class=&quot;language-text&quot;&gt;eksctl&lt;/code&gt; version and make sure it is at least 0.1.31.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;eksctl version&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Once you have installed &lt;code class=&quot;language-text&quot;&gt;eksctl&lt;/code&gt; and setup &lt;code class=&quot;language-text&quot;&gt;aws-cli&lt;/code&gt; you can create and deploy your EKS cluster in one command&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;eksctl create cluster &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;token parameter variable&quot;&gt;--name&lt;/span&gt; prod &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;token parameter variable&quot;&gt;--version&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1.12&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
--nodegroup-name standard-workers &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
--node-type t3.medium &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;token parameter variable&quot;&gt;--nodes&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
--nodes-min &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
--nodes-max &lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
--node-ami auto&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will give you the same exact setup you would get from the management console tutorial. The &lt;code class=&quot;language-text&quot;&gt;name&lt;/code&gt; parameter is what you want to name the EKS cluster. The &lt;code class=&quot;language-text&quot;&gt;version&lt;/code&gt; parameter is the version of kubernetes to use to deploy (1.12 is the newest at the time of this publication). The &lt;code class=&quot;language-text&quot;&gt;nodegroup-name&lt;/code&gt; parameter is the name of the worker nodes Cloudformation stack you will create. The &lt;code class=&quot;language-text&quot;&gt;node-type&lt;/code&gt; is the type of EC2 instance to use. The &lt;code class=&quot;language-text&quot;&gt;nodes&lt;/code&gt; parameter is how many worker nodes you want running normally in your EKS cluster. &lt;code class=&quot;language-text&quot;&gt;Nodes-min&lt;/code&gt; is the minimum number of nodes to ever have running and &lt;code class=&quot;language-text&quot;&gt;nodes-max&lt;/code&gt; is the maximum number of nodes you can ever have running. This is used when you are rolling out new deployments. When you deploy a change to your EKS cluster, it will start up a new node with this new code so you will have 4 nodes running at this time (3 with old code, 1 with new code). Then once you have a node up and running with new code, an old node will spin down and a new node will spin up with the new code. This will continue until you have 3 new nodes running with your new code. The last parameter is &lt;code class=&quot;language-text&quot;&gt;node-ami&lt;/code&gt; which is the Amazon Machine Image to start the EC2 instances with. By setting it to auto it will automatically pick the one for your given region.&lt;/p&gt;
&lt;p&gt;This command should take about 10-15 minutes to run and you should see an output that tells you what phase the creation and deployment script is on. The output should look something like&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;[ℹ]  using region us-west-2
[ℹ]  setting availability zones to [us-west-2b us-west-2c us-west-2d]
[ℹ]  subnets for us-west-2b - public:192.168.0.0/19 private:192.168.96.0/19
[ℹ]  subnets for us-west-2c - public:192.168.32.0/19 private:192.168.128.0/19
[ℹ]  subnets for us-west-2d - public:192.168.64.0/19 private:192.168.160.0/19
[ℹ]  nodegroup &quot;standard-workers&quot; will use &quot;ami-0abcb9f9190e867ab&quot; [AmazonLinux2/1.12]
[ℹ]  creating EKS cluster &quot;prod&quot; in &quot;us-west-2&quot; region
[ℹ]  will create 2 separate CloudFormation stacks for cluster itself and the initial nodegroup
[ℹ]  if you encounter any issues, check CloudFormation console or try &apos;eksctl utils describe-stacks --region=us-west-2 --name=prod&apos;
[ℹ]  2 sequential tasks: { create cluster control plane &quot;prod&quot;, create nodegroup &quot;standard-workers&quot; }
[ℹ]  building cluster stack &quot;eksctl-prod-cluster&quot;
[ℹ]  deploying stack &quot;eksctl-prod-cluster&quot;
[ℹ]  building nodegroup stack &quot;eksctl-prod-nodegroup-standard-workers&quot;
[ℹ]  deploying stack &quot;eksctl-prod-nodegroup-standard-workers&quot;
[✔]  all EKS cluster resource for &quot;prod&quot; had been created
[✔]  saved kubeconfig as &quot;/Users/user/.kube/config&quot;
[ℹ]  adding role &quot;arn:aws:iam::ACCOUNT_ID:role/eksctl-prod-nodeg-NodeInstanceRole-IJP4S12W3020&quot; to auth ConfigMap
[ℹ]  nodegroup &quot;standard-workers&quot; has 0 node(s)
[ℹ]  waiting for at least 1 node(s) to become ready in &quot;standard-workers&quot;
[ℹ]  nodegroup &quot;standard-workers&quot; has 3 node(s)
[ℹ]  node &quot;ip-192-168-22-17.us-west-2.compute.internal&quot; is not ready
[ℹ]  node &quot;ip-192-168-32-184.us-west-2.compute.internal&quot; is ready
[ℹ]  kubectl command should work with &quot;/Users/user/.kube/config&quot;, try &apos;kubectl get nodes&apos;
[✔]  EKS cluster &quot;prod&quot; in &quot;us-west-2&quot; region is ready&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now that you have created and deployed your cluster you should be ready to deploy your application to your worker nodes.&lt;/p&gt;
&lt;h3&gt;Deploying your application to EKS worker nodes&lt;/h3&gt;
&lt;p&gt;The following steps are what differs from AWS’s tutorial. There are two approaches. One approach is to create a deployment file, which will contain the information needed to deploy your application’s Docker image(s) to your worker nodes and setup a load balancer in front of them. You then apply this deployment to your EKS cluster using &lt;code class=&quot;language-text&quot;&gt;kubectl&lt;/code&gt;. The second approach is to run individual commands using &lt;code class=&quot;language-text&quot;&gt;kubectl&lt;/code&gt; to manually create the load balancer and set the Docker image(s) on the worker nodes. We took the first approach by taking information from this &lt;a href=&quot;https://blog.alterway.fr/en/kubernetes-101-launch-your-first-kubernetes-app.html&quot;&gt;tutorial&lt;/a&gt;, so I will go over that one.
First you need to setup your &lt;code class=&quot;language-text&quot;&gt;deployment.yml&lt;/code&gt; so that you can tell your EKS cluster how you want to deploy your application(s) to it. This is similar to what our YAML file looks like for deploying our Next.js app to EKS and putting a load balancer in front of it.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; apps/v1beta1
&lt;span class=&quot;token key atrule&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Deployment
&lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;deployment
  &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
&lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;replicas&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;matchLabels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
    &lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;containers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
          &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;TAG
          &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;containerPort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3000&lt;/span&gt;

&lt;span class=&quot;token punctuation&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Service
&lt;span class=&quot;token key atrule&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1
&lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;service
&lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; LoadBalancer
  &lt;span class=&quot;token key atrule&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;protocol&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; TCP
      &lt;span class=&quot;token key atrule&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;80&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;targetPort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The main thing to notice here is this part&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;containers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
      &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ACCOUNT_ID.dkr.ecr.us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;1.amazonaws.com/app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;TAG
      &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;containerPort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here we define the containers we want our worker nodes to use. The image value points to a Docker image we have stored on AWS ECR with our Next.js application in it and runs on port 3000. Then if you look at our load balancer definition&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Service
&lt;span class=&quot;token key atrule&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; v1
&lt;span class=&quot;token key atrule&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;service
&lt;span class=&quot;token key atrule&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; LoadBalancer
  &lt;span class=&quot;token key atrule&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;staging
  &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;protocol&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; TCP
      &lt;span class=&quot;token key atrule&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;80&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;targetPort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can see that we run the load balancer on &lt;code class=&quot;language-text&quot;&gt;port&lt;/code&gt; 80 but set the &lt;code class=&quot;language-text&quot;&gt;targetPort&lt;/code&gt; to 3000 so it forwards the traffic to our Docker container’s port.&lt;/p&gt;
&lt;p&gt;Once you have created your &lt;code class=&quot;language-text&quot;&gt;deployment.yml&lt;/code&gt;, you can deploy your stack using the command &lt;code class=&quot;language-text&quot;&gt;kubectl create -f deployment.yml&lt;/code&gt;. This will start your first deployment to your stack and give you some output telling you what’s being created. You can then run the command &lt;code class=&quot;language-text&quot;&gt;kubectl get services&lt;/code&gt; to get your load balancer information and the external IP that it is accessible on. The result of this will look something like this.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;NAME                  TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
app-staging-service   LoadBalancer   10.23.249.131   35.195.136.97   80:32750/TCP   1m&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you can’t see your full external IP address you can also run the following command &lt;code class=&quot;language-text&quot;&gt;kubectl describe services app-staging-service&lt;/code&gt; to see a more detailed view of the service and it’s full external IP.&lt;/p&gt;
&lt;h3&gt;Updating your application’s Docker image&lt;/h3&gt;
&lt;p&gt;Once you have deployed for the first time, you are going to want to make changes to your app’s Docker image and deploy those changes to your EKS cluster. In order to do this all you need to do is update the Docker image your worker nodes are using and wait for it to rollout to all of them. You can do this by using the following command&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;kubectl &lt;span class=&quot;token builtin class-name&quot;&gt;set&lt;/span&gt; image deployment/app-staging-deployment app-staging&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/app-staging:NEW_TAG&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This command rolls out an updated image to your &lt;code class=&quot;language-text&quot;&gt;app-staging&lt;/code&gt; containers. You just need to specify the new container in your registry with the correct tag. After you run this command you can run &lt;code class=&quot;language-text&quot;&gt;kubectl rollout status -w deployment/app-staging-deployment&lt;/code&gt; to check the status of your deployment. It should tell you what is happening in your deployment and return once the deployment is complete. If you deployment seems like it is stuck you should run the command &lt;code class=&quot;language-text&quot;&gt;kubectl get pods&lt;/code&gt; which will show you what pods are running. If one of them is in an infinite crash back loop you can use the following command to roll back your deployment &lt;code class=&quot;language-text&quot;&gt;kubectl rollout undo deployment/app-staging-deployment&lt;/code&gt;. But assuming your deployment is successful, now you’ve successfully created, deployed, and updated your AWS EKS cluster!&lt;/p&gt;
&lt;h3&gt;Additional Resources&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/getting-started-console.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/getting-started-console.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/54109603/how-to-use-docker-image-in-ecr-with-aws-eks&quot;&gt;https://stackoverflow.com/questions/54109603/how-to-use-docker-image-in-ecr-with-aws-eks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://blog.alterway.fr/en/kubernetes-101-launch-your-first-kubernetes-app.html&quot;&gt;https://blog.alterway.fr/en/kubernetes-101-launch-your-first-kubernetes-app.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://codeburst.io/getting-started-with-kubernetes-deploy-a-docker-container-with-kubernetes-in-5-minutes-eb4be0e96370&quot;&gt;https://codeburst.io/getting-started-with-kubernetes-deploy-a-docker-container-with-kubernetes-in-5-minutes-eb4be0e96370&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.edureka.co/blog/amazon-eks/&quot;&gt;https://www.edureka.co/blog/amazon-eks/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/weaveworks/eksctl&quot;&gt;https://github.com/weaveworks/eksctl&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Setting Up a Next.js Docker Container and Publishing it to AWS ECR]]></title><description><![CDATA[The first step in “dockerizing” an application is to download Docker onto your local machine. Personally we develop locally on macs, so we…]]></description><link>https://boredhacking.com/next-js-docker-ecr/</link><guid isPermaLink="false">https://boredhacking.com/next-js-docker-ecr/</guid><pubDate>Mon, 13 May 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The first step in “dockerizing” an application is to download Docker onto your local machine. Personally we develop locally on macs, so we downloaded &lt;a href=&quot;https://docs.docker.com/v17.12/docker-for-mac/install/#what-to-know-before-you-install&quot;&gt;Docker for Mac&lt;/a&gt; using the tutorial in that link. Once you have Docker installed locally, you need to create a &lt;code class=&quot;language-text&quot;&gt;Dockerfile&lt;/code&gt; in the root of your Next.js application. We created the following &lt;code class=&quot;language-text&quot;&gt;Dockerfile&lt;/code&gt; for our Next.js app.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;FROM node:10-alpine

ENV PORT 3000

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app

RUN npm run build
EXPOSE 3000

CMD [ &quot;npm&quot;, &quot;start&quot; ]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first line &lt;code class=&quot;language-text&quot;&gt;FROM node:10-alpine&lt;/code&gt; is the base Docker image we used to create our application’s image. We developed our application using node version 10.15.3 so we used a base container with the corresponding node version. Another thing to note here is that it is an &lt;em&gt;alpine&lt;/em&gt; container. The main reason for using alpine containers as your base image is that they are smaller. They remove unnecessary bloat your application doesn’t need to run. By switching our application from using the &lt;code class=&quot;language-text&quot;&gt;node:10&lt;/code&gt; base image to &lt;code class=&quot;language-text&quot;&gt;node:10-alpine&lt;/code&gt;, we were able to shrink our Docker image from over 400kb to around 70kb (more than 75% savings in size). To learn about more reasons why an alpine image is normally better for creating Docker images, take a look at the following &lt;a href=&quot;https://nickjanetakis.com/blog/the-3-biggest-wins-when-using-alpine-as-a-base-docker-image&quot;&gt;link&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The next line is &lt;code class=&quot;language-text&quot;&gt;ENV PORT 3000&lt;/code&gt;, which sets our application’s port that it will run on within the Docker container. We also set some other environment variables in our real &lt;code class=&quot;language-text&quot;&gt;Dockerfile&lt;/code&gt;. Since this is a frontend application without any secure credentials in it, we found it easiest to just set all of our environment variables directly in the &lt;code class=&quot;language-text&quot;&gt;Dockerfile&lt;/code&gt;. There are two other approaches to setting a Docker image’s environment variables we came across while developing. The first is to use a &lt;code class=&quot;language-text&quot;&gt;docker_compose.yml&lt;/code&gt; file that you do not commit to your github repo and use locally to create the Docker image. You can either put the environment variables directly in the &lt;code class=&quot;language-text&quot;&gt;docker_compose.yml&lt;/code&gt; or have it use your &lt;code class=&quot;language-text&quot;&gt;.env&lt;/code&gt; file. Here is a &lt;a href=&quot;https://docs.docker.com/compose/environment-variables/&quot;&gt;link&lt;/a&gt; describing how to do this from Docker’s documentation. Another approach that we came across is to create a secret Docker image that just sets environment variables and then use that as one of your base images in your &lt;code class=&quot;language-text&quot;&gt;Dockerfile&lt;/code&gt;. You would build and push this Docker image to a registry locally so that your secrets are never linked, and you can still use them in your application. But once again we found this unnecessary since our environment variables for our frontend application are viewable when you visit our web app in the browser anyways.&lt;/p&gt;
&lt;p&gt;The next two lines &lt;code class=&quot;language-text&quot;&gt;RUN mkdir -p /usr/src/app&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;WORKDIR /usr/src/app&lt;/code&gt; create a directory in our container for our application’s code to reside in and then sets the working directory to &lt;code class=&quot;language-text&quot;&gt;/usr/src/app&lt;/code&gt;. By setting the working directory, we will run all of our commands in this directory. We then copy our &lt;code class=&quot;language-text&quot;&gt;package.json&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;package-lock.json&lt;/code&gt; into our app directory using &lt;code class=&quot;language-text&quot;&gt;COPY package*.json /usr/src/app/&lt;/code&gt;. This allows us to then download our dependencies into our application’s directory using &lt;code class=&quot;language-text&quot;&gt;RUN npm install&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Finally we copy the rest of our application using &lt;code class=&quot;language-text&quot;&gt;COPY . /usr/src/app&lt;/code&gt; into the app’s directory and call &lt;code class=&quot;language-text&quot;&gt;RUN npm run build&lt;/code&gt; to create our production build files. &lt;code class=&quot;language-text&quot;&gt;EXPOSE 3000&lt;/code&gt; exposes port 3000 on the container, and finally we run the last command &lt;code class=&quot;language-text&quot;&gt;CMD [ &quot;npm&quot;, &quot;start&quot; ]&lt;/code&gt; to startup our production build of our web application in the container. With that we have a docker image that we can build and run locally, or deploy to an Docker registry and run on a server.&lt;/p&gt;
&lt;h3&gt;Deploying to ECR&lt;/h3&gt;
&lt;p&gt;Now that we have our &lt;code class=&quot;language-text&quot;&gt;Dockerfile&lt;/code&gt; we can create our Docker image and deploy it to our Docker image registry which in this case will be AWS Elastic Container Registry (ECR).&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First step is to make sure you have an AWS account and to download the aws-cli. This can be achieved by using the following &lt;a href=&quot;https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html&quot;&gt;tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Next you need to create an image repository on ECR, which AWS also has a great tutorial for &lt;a href=&quot;https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-create.html&quot;&gt;here&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;View the push commands in the repo to find out how to push an image to the repo&lt;/li&gt;
&lt;li&gt;The first command is &lt;code class=&quot;language-text&quot;&gt;$(aws ecr get-login --no-include-email --region AWS_REGION)&lt;/code&gt;. This command will login to docker on your local machine using your AWS credentials so you can push your image to your repository. This part of the command &lt;code class=&quot;language-text&quot;&gt;aws ecr get-login --no-include-email --region AWS_REGION&lt;/code&gt; is used to get your login credentials from aws and returns a script you can run to login to Docker. By wrapping it in &lt;code class=&quot;language-text&quot;&gt;$()&lt;/code&gt; you are telling your console to execute the result of &lt;code class=&quot;language-text&quot;&gt;aws ecr get-login --no-include-email --region AWS_REGION&lt;/code&gt;. Make sure you have aws-cli setup locally too with your AWS credentials in your &lt;code class=&quot;language-text&quot;&gt;.aws&lt;/code&gt; directory. You also must specify what region you created the ECR instance in.&lt;/li&gt;
&lt;li&gt;The next command &lt;code class=&quot;language-text&quot;&gt;docker build -t REPOSITORY_NAME:COMMIT_ID -f Dockerfile .&lt;/code&gt; will build your Docker image from the specified &lt;code class=&quot;language-text&quot;&gt;Dockerfile&lt;/code&gt; following &lt;code class=&quot;language-text&quot;&gt;-f&lt;/code&gt; in the current directory &lt;code class=&quot;language-text&quot;&gt;.&lt;/code&gt;. If you have multiple &lt;code class=&quot;language-text&quot;&gt;Dockerfile&lt;/code&gt;’s like &lt;code class=&quot;language-text&quot;&gt;Dockerfile.staging&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;Dockerfile.production&lt;/code&gt;, the &lt;code class=&quot;language-text&quot;&gt;-f&lt;/code&gt; command allows you to specify which one to use to build your Docker image. &lt;code class=&quot;language-text&quot;&gt;REPOSITORY_NAME&lt;/code&gt; is the name of our ECR repository, not our git repository. What comes after the colon(:) following the &lt;code class=&quot;language-text&quot;&gt;REPOSITORY_NAME&lt;/code&gt; will be the tag. We tag our Docker image using our git commit sha during our CI/CD deployment. This way we can keep track of what code is in each Docker image in our repo and rollback if necessary.&lt;/li&gt;
&lt;li&gt;Then we want to tag the Docker image we just created using &lt;code class=&quot;language-text&quot;&gt;docker tag REPOSITORY_NAME:COMMIT_ID ACCOUNT_ID.dkr.ecr.AWS_REGION.amazonaws.com/REPOSITORY_NAME:COMMIT_ID&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Finally push your image your Docker image to ECR using &lt;code class=&quot;language-text&quot;&gt;docker push ACCOUNT_ID.dkr.ecr.AWS_REGION.amazonaws.com/REPSITORY_NAME:COMMIT_ID&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This shows you how to deploy to ECR using manual commands, but we have setup our CI/CD platform to run the commands for us so we have automatic deployments when we push to our staging or production branches on Github.&lt;/p&gt;
&lt;h3&gt;Additional Resources&lt;/h3&gt;
&lt;p&gt;The following resources were used to come up with this approach and write this post&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://medium.com/@khwsc1/a-simple-react-next-js-app-development-on-docker-6f0bd3f78c2c&quot;&gt;https://medium.com/@khwsc1/a-simple-react-next-js-app-development-on-docker-6f0bd3f78c2c&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://medium.com/google-cloud/next-js-tutorial-deploy-to-docker-on-google-cloud-container-engine-6b0c19dd8ecb&quot;&gt;https://medium.com/google-cloud/next-js-tutorial-deploy-to-docker-on-google-cloud-container-engine-6b0c19dd8ecb&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Setting Up Google Optimize in a React App Using Segment]]></title><description><![CDATA[We recently decided to migrate to Google Optimize(GO or Optimize from here on) as our A/B experiment test system for our frontend SPA which…]]></description><link>https://boredhacking.com/google-optimize-in-react/</link><guid isPermaLink="false">https://boredhacking.com/google-optimize-in-react/</guid><pubDate>Sat, 27 Apr 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;We recently decided to migrate to Google Optimize(GO or Optimize from here on) as our A/B experiment test system for our frontend SPA which is built using React and Redux. We weren’t quite getting everything we wanted out of our previous vendor, and GO seemed like a promising system with simple integration to Universal Analytics, Google Tag Manager, and all of Google’s products which some of which we use heavily. However, there aren’t very many resources online that talk about using GO for a SPA, so I hope this post can be used by other developers to skip some of the pitfalls we fell into.&lt;/p&gt;
&lt;h3&gt;Initial Setup&lt;/h3&gt;
&lt;p&gt;We use Segment.io to deploy Google Analytics(GA) and Google Tag Manager(GTM) on our site. Therefore we decided to also use it to deploy Google Optimize. This causes some problems that we will go over in this post, and therefore something we are thinking about revisiting(possibly loading GA and GO on our SPA ourselves). But if you deploy your GA script using Segment you must also deploy GO using segment because GA needs to be loaded on the page before GO can be loaded on the page. If you do not want to deploy GO using Segment you should be able to follow GO’s guidelines for setup placing the GO script under your GA script in the head of your page, using the proper container ID’s in the script, and then adding your page hiding snippet on your page.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;First make sure you setup a GO account and a container for you application in your account. You can follow Google’s documentation to do the &lt;a href=&quot;https://support.google.com/optimize/answer/6211921?hl=en&amp;#x26;ref_topic=7310368&quot;&gt;account setup&lt;/a&gt;. The initial setup is the same for any application and their documentation is fairly straightforward to follow.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once you have setup your GO container for your application, you must take the container ID and set it in Segment on your Google Analytics Destination. There is a setting called &lt;code class=&quot;language-text&quot;&gt;Optimize Container ID&lt;/code&gt; where you can place the container id. It Should start with a &lt;code class=&quot;language-text&quot;&gt;GTM-&lt;/code&gt; and be followed by a combination of numbers and letters.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now your application should be connected to your GO container and you should be ready to start deploying experiments to your SPA. However, the GO page hiding snippet, which is used to hide your website until GO is loaded, will not work with this setup. Since we are loading GO using Segment it is loaded asynchronously as part of Segment’s analytics script. The major problem is that our &lt;code class=&quot;language-text&quot;&gt;dataLayer&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;gaData&lt;/code&gt; variable are not initialized until after Segment finishes loading our GA script. So instead of using GO’s page hiding snippet, we’ve created our own version of it. Using our redux state we keep track of whether or not GO has been loaded on the page, and we display a loading screen on our website until GO is loaded or until our reducer times out. Our reducer and action creator code looks like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; combineReducers &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;redux&quot;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; constants &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token constant&quot;&gt;LOAD_GO&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;LOAD_GO&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token constant&quot;&gt;LOAD_GO_SUCCESS&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;LOAD_GO_SUCCESS&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token constant&quot;&gt;LOAD_GO_FAILURE&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;LOAD_GO_FAILURE&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;loadGO&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;dispatch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;dispatch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; constants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;LOAD_GO&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; maxWaitTime &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;300&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; currentWait &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; goObserver &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setInterval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;gaData&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;dispatch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; constants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;LOAD_GO_SUCCESS&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;clearInterval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;goObserver&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;currentWait &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; maxWaitTime&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;dispatch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; constants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;LOAD_GO_FAILURE&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;clearInterval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;goObserver&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      currentWait&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;loadingReducer&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;state &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; action&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;action&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;type&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; constants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;LOAD_GO&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; constants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;LOAD_GO_SUCCESS&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; constants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;LOAD_GO_FAILURE&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; state
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;combineReducers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; loadingReducer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;We then check the value in state whether or not GO has been loaded on our layout which wraps all of our application. This gives us functionality similar to the page hiding snippet but allows us to use more on brand loaders instead of a blank white screen. However, an obvious drawback to this is the fact that every time a user comes to our website they will initially see a loader but the same would be true for seeing a blank white page with the GO page hiding snippet. Something you can do to limit this effect is to remove the loader when you are not currently running any GO experiments on your website.&lt;/p&gt;
&lt;h3&gt;Experiment Setup&lt;/h3&gt;
&lt;p&gt;Now I will go over how to setup a GO experiment in your SPA app. I will not go over in detail the actual setup of the experiment in GO because this varies on the use case. However, one important thing to note is how you target users for the experiment. There are two ways to target a user for a given A/B experiment: on page load or by a custom event. Since SPA’s only load once(on the initial visit to the website), you need to be careful when targeting users on page load. You generally should only use the on load target option if you want the user to be targeted on entering any page of your website or you know every entry for a user for a given experiment. This way the user will enter the experiment on initial page load. If you do not want every user to be targeted in an experiment and you only want user’s who reach a certain page(after entering from another page) in your application to be targeted, then you will most likely have to fire a custom event on that page to enter the user in the experiment. You can fire the event as you fire any other GA event, but you want to make sure you have the experiment value on render so you know what variation to show. Besides that the flow for setting up a GO experiment in our React app goes as follows.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Set up the experiment in GO with your variations and targeting rules.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;(Optional) Setup custom goals in your UA/GA account that you can track in your GO experiment. This requires knowing an event’s category, label, action, and/or value that you want to track.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set up your GO experiment to track a given event. We send events using segment that are forwarded to UA. So we call events using &lt;code class=&quot;language-text&quot;&gt;analytics.track(…)&lt;/code&gt; and then can target an event by it’s category, action, value, and/or label in GO. But you can also set up goals in GA and then GO will allow you to pick it as a pre-made goal, instead of defining it directly in GO. This is useful for events you already track in GA.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once you have the experiment setup we must use the experiment ID in our application. We set it as an environment variable for a given experiment because we have staging and production experiments for testing purposes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Get the experiment value in your application to know which variation to show. We use the following code to check our &lt;code class=&quot;language-text&quot;&gt;window.gaData&lt;/code&gt; value to determine the current experiment variation on a given page. Experiment values are stored in the &lt;code class=&quot;language-text&quot;&gt;window.gaData&lt;/code&gt; value under the key that is your UA container ID. All your experiments will then be stored in this context using the key of the experiment ID. Each experiment stores a single string value that corresponds to the variation. The control is defined as the string &lt;code class=&quot;language-text&quot;&gt;&apos;0&apos;&lt;/code&gt; and all variations will increase by 1(still as a string). We use the following code to determine the variation for a given experiment. It is good to handle null and undefined values throughout your code to default to the control.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;getVariantId&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;experimentId&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;UA_ID&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; process&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;UA_ID&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;gaData &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;gaData&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;UA_ID&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;gaData&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;UA_ID&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;experiments
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;gaData&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;UA_ID&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;experiments&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;experimentId&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;0&quot;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;0&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And as I previously stated we have separate staging and production containers for GO so we can test experiments in our QA environment. Therefore all of UA, GO, and experiment ID’s are stored as environment variables. The drawback to this is that we then have to recreate the experiment in our production GO container and make sure all the proper ID’s are set in our environment variables, but it allows us to avoid problems in the experiment setup in production.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;h4&gt;Cons&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The initial setup was a little cumbersome and difficult to figure out with the lack of online resources.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;GO initially didn’t allow you to edit experiments once they are running, which meant you had to clone an experiment and restart if there was an error. (However, it appears they recently added the feature to allow you to stop and edit an experiment which fixes this problem.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Using GO in a SPA is a little complex and prone to errors, like not having the experiment loaded on the page if your targeting isn’t setup correctly or you don’t wait for GO to load on your page. This can also cause your page to look like it’s taking a while to render if you display a loader while you do this.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Setting up new experiments require’s code deploys.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Initial learning curve of using GO and setting up experiments.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;Pros&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Seamless integration with GA/UA.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once you have done the initial setup you can easily follow a recipe to setup new experiments which make them easy to set up in the future.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can trigger events to track using Segment’s analytics script like all of your other events&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The targeting feature is very explicit, allowing you to target a user on a number of things even firing your own event or using first party cookies.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Overall we are happy with our experience with GO. Most of the cons we have for using it involve initial setup and learning curve. But once you have spent some time with it, everything becomes much easier and streamlined. The event tracking and reporting is very nice because it is integrated with UA. So if you are using UA for reporting and tracking it’s a very nice tool to use. We also use GO for a rails application, which allows us to use the GO editor which is really user friendly and allows you to easily create variations for static websites. This is definitely a pro but not something that we get to utilize in our SPA.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Pipelining Segment Events Back Into Our eCommerce Store]]></title><description><![CDATA[As a data-driven eCommerce company, Rockets of Awesome deals with tens of thousands of segment events everyday. And although segment handles…]]></description><link>https://boredhacking.com/segment-event-pipeline/</link><guid isPermaLink="false">https://boredhacking.com/segment-event-pipeline/</guid><pubDate>Sat, 27 Apr 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;As a data-driven eCommerce company, Rockets of Awesome deals with tens of thousands of segment events everyday. And although segment handles sending these to most outside services, there are certain instances when we want to update our model attributes based on frontend events. So in order to handle this process we built a Segment Drain. Our Segment Drain filters our segment events for the ones we want and then forward these events along to our eCommerce store. We wanted to stream this frontend information to our backend reliably and as quickly as possible so we utilized some AWS services such as API Gateways, Lambdas, and Kinesis Data Streams.&lt;/p&gt;
&lt;h3&gt;Architecture&lt;/h3&gt;
&lt;p&gt;The overall architecture of our system relies on a few different systems.
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/1fd23676aa364f1b2f32e52ef9e8f228/29007/architecture.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 32.43243243243243%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAIAAABM9SnKAAAACXBIWXMAAAsSAAALEgHS3X78AAABR0lEQVQY0y2Pz0rDQBDG8ww+jWdPPoSH+gheeykoFEPBg4KH6qX0IIhYQWiL1VoVcxFpTLRF/AO2FpqYhja7+bOzu1lnUZjLN/P95psxTk4bq2vr582WUgoYTBd+nCacAeN8MZmOnaHIJWP89bE1fmkDF1zI0V1jZl9KpYwts7K0vLKzu4fw58/4PRh9zL7nNMoAnJv7s6PjiETA5W1j2+1UEAYh7cPipLmfIxwEwUW7TUiEcJgsfBKGdJ6wVAiRxDGhlAH68yylLKUYq/tpyjkHAANFnue2bfd6Pd/zcQVehjPGmDYKCVnG0phLiZUl8TzwADSpYfQRQkqlUqFQuOp2dX4YVqtV0zSHgwFKp7b5VivqTKW+HjpPBxu5gD/e+Aup1+vlctl1XXRTSvv9vmVZnjfFx7xna+Zc62+5iLxR6HQk/4d/AfKnO7khPdrzAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Architecture&quot;
        title=&quot;&quot;
        src=&quot;/static/1fd23676aa364f1b2f32e52ef9e8f228/fcda8/architecture.png&quot;
        srcset=&quot;/static/1fd23676aa364f1b2f32e52ef9e8f228/12f09/architecture.png 148w,
/static/1fd23676aa364f1b2f32e52ef9e8f228/e4a3f/architecture.png 295w,
/static/1fd23676aa364f1b2f32e52ef9e8f228/fcda8/architecture.png 590w,
/static/1fd23676aa364f1b2f32e52ef9e8f228/efc66/architecture.png 885w,
/static/1fd23676aa364f1b2f32e52ef9e8f228/c83ae/architecture.png 1180w,
/static/1fd23676aa364f1b2f32e52ef9e8f228/29007/architecture.png 1600w&quot;
        sizes=&quot;(max-width: 590px) 100vw, 590px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;Segment.io&lt;/h3&gt;
&lt;p&gt;The first system in our architecture is our frontend client. Our react client is our of our sources for segment events. We create event using segments analytics javascript library, which pushes events to Segment. This allows us to forward events to our different destinations. We can create multiple destinations for our segment events to be pushed too. The one that is important to us for this Segment Drain is the web-hook destination. Using the web-hook destination, we can forward all of our segment events to our AWS services to be processed.&lt;/p&gt;
&lt;h3&gt;AWS&lt;/h3&gt;
&lt;p&gt;Our AWS architecture is split up into 4 parts
The first part of the architecture is the API Gateway. The API Gateway is the “Front Door” for other services/applications. Amazon API Gateway handles all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls. In our case we are using our API Gateway as a proxy for our Lambda. This basically just means that we use it to forward requests from our web-hook to our first Lambda function. It acts as a broker of HTTP requests from the web-hook to the lambda function.
Next in the architecture is our first Lambda function. We have two different Lambda functions in our architecture. For those who aren’t already aware, Lambda functions are blocks of code that we can run without having to provision or manage servers. Lambda functions have a second added benefit of only having to pay for the time your code is running. Our first Lambda function acts as a filtering system. We use it to only forward on the segment events that we care about instead of having to run all of our events through our entire data pipeline. So our Lambda function has a list of the events we will want to forward on, and then publishes these events to our Kinesis Stream, discarding all unnecessary events. This has the benefit of limiting the load that we put on our Kinesis Stream and the rest of our system in general.
Here is our Lambda for filtering and forwarding events to our Kinesis Stream:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;use strict&quot;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;AWS&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;aws-sdk&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; events &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;./forwardable_events&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; kinesisConstants &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;./kinesisConstants&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

exports&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function-variable function&quot;&gt;handler&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; context&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; response &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;statusCode&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; kinesis &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;AWS&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Kinesis&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;apiVersion&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; kinesisConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;API_VERSION&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;region&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; kinesisConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;REGION&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;findEvent&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;eventName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      events&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;FORWARDABLE_EVENTS&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;hasOwnProperty&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;eventName&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
      events&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;FORWARDABLE_EVENTS&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;eventName&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;enabled&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;savePayload&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; params &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;Data&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;PartitionKey&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; kinesisConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;PARTITION_KEY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;StreamName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; kinesisConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;STREAM_NAME&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    kinesis&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;putRecord&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;params&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;err&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; data&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;statusCode &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;500&lt;/span&gt;
        response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;error recording to Kinesis stream&quot;&lt;/span&gt;
        console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;response&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;message recorded to Kinesis stream&quot;&lt;/span&gt;
        console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; response&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; valid &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;findEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;event&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; params &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;StreamName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; kinesisConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;STREAM_NAME&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;valid&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    kinesis&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;describeStream&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;params&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;err&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; data&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;statusCode &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;500&lt;/span&gt;
        response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;response&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;//Make sure stream is able to take new writes (ACTIVE or UPDATING are good)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
          data&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;StreamDescription&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;StreamStatus &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt;
            kinesisConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;STATE&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;ACTIVE&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;
          data&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;StreamDescription&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;StreamStatus &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt;
            kinesisConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;STATE&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;UPDATING&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;token function&quot;&gt;savePayload&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
          response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;statusCode &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;500&lt;/span&gt;
          response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;stream not stable&quot;&lt;/span&gt;
          &lt;span class=&quot;token function&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;response&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;invalid event: &quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;event
    &lt;span class=&quot;token function&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; response&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The next part of our system is a Kinesis Stream. Amazon Kinesis Data Streams enable you to build custom applications that process or analyze streaming data for specialized needs. Kinesis Data Streams can continuously capture and store terabytes of data per hour. You can also emit data from Kinesis Data Streams to other AWS services such as Amazon Simple Storage Service (Amazon S3), Amazon Redshift, Amazon EMR, and AWS Lambda. In our case we emit our data to another Lambda function.&lt;/p&gt;
&lt;p&gt;Our second Lambda function we use to forward all our filtered events to our backend system. This lambda function polls our Kinesis Stream for events, processes batches of events, and then uses HTTP requests to forward them to our message broker system.&lt;/p&gt;
&lt;p&gt;Here is our Lambda that polls our Kinesis Stream and forwards the events:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;use strict&quot;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; request &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;request&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

exports&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function-variable function&quot;&gt;handler&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; context&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Records&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; json &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Buffer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;record&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;kinesis&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;base64&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;utf8&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; options &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;process&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;PUB_SUB_URL&lt;/span&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;events/segment_drain&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token string-property property&quot;&gt;&quot;Content-Type&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token literal-property property&quot;&gt;Authorization&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;Bearer &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;process&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;PUB_SUB_AUTH_TOKEN&lt;/span&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; json&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token function&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;options&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;err&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; res&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;res &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;statusCode &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;statusCode &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;201&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;succeed&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;res&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;fail&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;statusCode&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Message Broker&lt;/h3&gt;
&lt;p&gt;Our backend system has two components in this pipeline. One is a pub-sub message broker system that we use to handle all events being dispatched between our eCommerce store and outside resources(such as Segment). So our last Lambda function forwards all events to this system which then passes the event along to our eCommerce store.&lt;/p&gt;
&lt;h3&gt;eCommerce Store&lt;/h3&gt;
&lt;p&gt;Our eCommerce store is built on Ruby on Rails, so it has a special controller that handles all our segment events. Each type of segment event we have has a special event class that tells our eCommerce store what to do with the payload. We accomplish this by creating a registry that registers a class for the event we want to process, and we can tell which class handles which events. We register each of our events in the registry in &lt;code class=&quot;language-text&quot;&gt;config/initializers/segment_events.rb&lt;/code&gt;. This allows our app to know all the registered events on load. Our controller gets the proper event class from our registry using the event type, and then each event class implements a &lt;code class=&quot;language-text&quot;&gt;process&lt;/code&gt; method that handles the payload and updates the appropriate models in our database, as well as running any other code that processes the event.&lt;/p&gt;
&lt;p&gt;Here is our code for our controller, registry, and events:&lt;/p&gt;
&lt;h4&gt;Controller&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre class=&quot;language-ruby&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Api&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;V1&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;SegmentController&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; Api&lt;span class=&quot;token double-colon punctuation&quot;&gt;::&lt;/span&gt;ApplicationController
      before_action &lt;span class=&quot;token symbol&quot;&gt;:authenticate_api_token!&lt;/span&gt;

      &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token method-definition&quot;&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;/span&gt;
        Segment&lt;span class=&quot;token double-colon punctuation&quot;&gt;::&lt;/span&gt;EventRegistry&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;klass_for&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;params&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token symbol&quot;&gt;:event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;params&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;process
        head &lt;span class=&quot;token symbol&quot;&gt;:created&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;Event Registry&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre class=&quot;language-ruby&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Segment&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Registry&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token method-definition&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;included&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;base&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      base&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;send&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token symbol&quot;&gt;:extend&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; ClassMethods&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ClassMethods&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token method-definition&quot;&gt;&lt;span class=&quot;token function&quot;&gt;klasses&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;options &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;default &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; options&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;fetch&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token symbol&quot;&gt;:default&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;registry &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;

      &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token method-definition&quot;&gt;&lt;span class=&quot;token function&quot;&gt;register&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;klass&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        registry&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;klass&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;event_name&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; klass
      &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;

      &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token method-definition&quot;&gt;&lt;span class=&quot;token function&quot;&gt;klass_for&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        registry&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;fetch&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;to_sym&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; default &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;

      &lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt;

      attr_accessor &lt;span class=&quot;token symbol&quot;&gt;:registry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token symbol&quot;&gt;:default&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;Registry&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre class=&quot;language-ruby&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Segment&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;EventRegistry&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;include&lt;/span&gt; Segment&lt;span class=&quot;token double-colon punctuation&quot;&gt;::&lt;/span&gt;Registry

    klasses default&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Segment&lt;span class=&quot;token double-colon punctuation&quot;&gt;::&lt;/span&gt;Events&lt;span class=&quot;token double-colon punctuation&quot;&gt;::&lt;/span&gt;BaseEvent
  &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;Base Event&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre class=&quot;language-ruby&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Segment&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Events&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;BaseEvent&lt;/span&gt;
      attr_reader &lt;span class=&quot;token symbol&quot;&gt;:payload&lt;/span&gt;

      &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token method-definition&quot;&gt;&lt;span class=&quot;token function&quot;&gt;initialize&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;payload&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token variable&quot;&gt;@payload&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; payload
      &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;

      &lt;span class=&quot;token comment&quot;&gt;# return nil when not implemented&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token method-definition&quot;&gt;&lt;span class=&quot;token function&quot;&gt;process&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;

      &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token method-definition&quot;&gt;&lt;span class=&quot;token function&quot;&gt;properties&lt;/span&gt;&lt;/span&gt;
        payload&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token symbol&quot;&gt;:properties&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;

      &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token method-definition&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;event_name&lt;/span&gt;&lt;/span&gt;
        name&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;demodulize&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;underscore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;to_sym
      &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;Registered Events&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre class=&quot;language-ruby&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# All registered segment events we want to process&lt;/span&gt;
Segment&lt;span class=&quot;token double-colon punctuation&quot;&gt;::&lt;/span&gt;EventRegistry&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;register&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Segment&lt;span class=&quot;token double-colon punctuation&quot;&gt;::&lt;/span&gt;Events&lt;span class=&quot;token double-colon punctuation&quot;&gt;::&lt;/span&gt;RegisteredEvent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And now we are ready to process and store streaming information from Segment events in our eCommerce store’s database!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Hello World]]></title><description><![CDATA[Hi I’m James Russo and this is my first attempt at a blog, so bear with me on this. I am well aware of my level of writing, so I apologize…]]></description><link>https://boredhacking.com/hello-world/</link><guid isPermaLink="false">https://boredhacking.com/hello-world/</guid><pubDate>Tue, 23 Apr 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Hi I’m James Russo and this is my first attempt at a blog, so bear with me on this. I am well aware of my level of writing, so I apologize in advance if any of my posts are hard to read or understand. I’ll try not to repeat too much of what is already in my &lt;a href=&quot;/about&quot;&gt;About Me&lt;/a&gt; section, so head over there if you want to find out more about me.&lt;/p&gt;
&lt;p&gt;This blog has been something I’ve wanted to do for a few years now, but obviously it was something I never devoted enough time to or got around to. I thought it would be a good way to help me try some new technologies and build my web development skills. My main goal of this blog is to detail projects or features I implement, problems I encounter during development, and my solutions to them. I hope by doing this that I am able to help someone else out and save them some time. Every once in a while I might talk about another topic as well or discuss something I find interesting.&lt;/p&gt;
&lt;p&gt;This blog is an MVP. I know it’s not perfect and I know it can use a lot of work. I’m hoping to incrementally add features and improve this site, because I like an iterative development process. Over the years I’ve thought of a few different technologies to implement this blog in. I’ve looked at building it in Flask, Ruby on Rails, React, Elixir, or some combination of those technologies. However, I’ve decided to go with Gatsby for the time being. Gatsby is a static site generator that allows you to develop using React. I use React extensively at work so I thought it would allow me to implement this fairly easy. Gatsby was introduced to me by my CTO at &lt;a href=&quot;https://rocketsofawesome.com&quot;&gt;Rockets of Awesome&lt;/a&gt;, Josh Stewart, and I’ve had a fairly good time using it. I started with the &lt;a href=&quot;https://github.com/gatsbyjs/gatsby-starter-blog&quot;&gt;Gatsby starter blog&lt;/a&gt; which was created by one of Gatsby’s creators Kyle Matthews. I’ve made some changes and added some dependencies, but I thought it was fairly straightforward to get started with. The blog setup and development will be discussed in a future post though.&lt;/p&gt;
&lt;p&gt;Thank you for visiting and I hope you enjoy reading this blog. My goal is to help at least one other developer with the work I post here. So if you find anything helpful feel free to reach out and let me know!&lt;/p&gt;</content:encoded></item></channel></rss>