<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Imagine Learning Engineering - Medium]]></title>
        <description><![CDATA[Imagine Learning edtech production team, passionate software and systems for language, literacy, and math instruction for all students from Pre-K up! - Medium]]></description>
        <link>https://medium.com/imaginelearning?source=rss----600b25e4e7c2---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Imagine Learning Engineering - Medium</title>
            <link>https://medium.com/imaginelearning?source=rss----600b25e4e7c2---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 03:25:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/imaginelearning" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scaling Model Context Protocol: From a Proxy to an Agent Gateway]]></title>
            <link>https://medium.com/imaginelearning/scaling-model-context-protocol-from-a-proxy-to-an-agent-gateway-91d91b3c604f?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/91d91b3c604f</guid>
            <category><![CDATA[agentic-workflow]]></category>
            <category><![CDATA[model-context-protocol]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[mcps]]></category>
            <dc:creator><![CDATA[Mason Price]]></dc:creator>
            <pubDate>Tue, 23 Jun 2026 20:03:49 GMT</pubDate>
            <atom:updated>2026-06-23T20:03:47.908Z</atom:updated>
            <content:encoded><![CDATA[<p>Almost a year ago, we wrote about a bet we made on Model Context Protocol (MCP): that one proxy could collapse our sprawl of internal tools, spanning services like AWS, ArgoCD, Jira, and Confluence, into a single endpoint engineers could reach from inside their IDE. We containerized a handful of stdio MCP servers behind a single HTTP interface, kept access read-only, and shipped it. It did what we hoped for. Engineers spent less time hunting for answers, onboarding got shorter, and the platform team fielded fewer “where do I find this” questions.</p><p>What we didn’t expect was what happened next. The proxy quietly stopped being a developer convenience and became the backbone of how we run agentic workflows at Imagine Learning. This article is about that evolution: how we re-platformed it, how it grew, and where we’re taking it.</p><p><strong>Moving to AgentGateway</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wq1QrjuJNw1R8fYnogdtwA.png" /></figure><p>The first version was held together by SuperGateway, which bridged our stdio servers to HTTP, with NGINX in front routing requests by path. One container ran two SuperGateway instances plus NGINX, with a hand-rolled log format and a config file we maintained by hand. It worked, but every new server meant a new routing block and a new process to supervise, and NGINX understood nothing about the protocol it was forwarding.</p><p>In July 2025 we replaced all of it with <a href="https://agentgateway.dev/">AgentGateway</a>, a proxy built specifically for MCP traffic. AgentGateway speaks MCP natively, so the stdio bridging, the routing, the CORS handling, and the health endpoint all folded into a single binary driven by one declarative config file. NGINX and SuperGateway disappeared from our Dockerfile entirely. A few weeks later we made the whole thing stateless, which let it scale cleanly in Kubernetes. Adding a server went from standing up a new process to adding a route in a YAML file.</p><p><strong>Betting on an Open Standard</strong></p><p>A month after we migrated, AgentGateway was donated to the Linux Foundation. Then in December 2025, the Linux Foundation announced the <a href="https://www.solo.io/blog/aaif-announcement-agentgateway">Agentic AI Foundation</a>, bringing the protocols themselves under neutral, open governance, including MCP from Anthropic, goose from Block, and AGENTS.md from OpenAI. And just this month, <a href="https://aaif.io/blog/agentgateway-joins-aaif-as-an-open-gateway-for-agentic-ai-infrastructure/">AgentGateway itself joined the AAIF</a> as a hosted project, putting the gateway under the same neutral governance as the protocols it speaks.</p><p>That matters because enterprises don’t standardize on single-vendor protocols; they standardize on open ones. The question organizations are asking now, how to secure and govern an agentic architecture built on MCP, is one we had been answering in production for months. We picked this pattern because it was pragmatic. The industry went on to make it a standard.</p><p><strong>From Developer Convenience to Agentic Coordination</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_aUwwmHDP9Ei-v0ZuBsE2g.png" /></figure><p>When the first article went out, the proxy fronted five servers. Today it fronts twelve, spanning developer references like AWS documentation and GitHub to operational tooling: deployment state, observability, cost reporting, contract testing, and dead-letter queues. Some are open-source servers and some we wrote ourselves; the gateway treats them all the same way, as stdio backends behind a route.</p><p>The original framing was developer efficiency, a human in an IDE reaching for a tool. That still holds, but it’s no longer the main event. The same fleet of servers is now a control plane for our agents. When an agent investigates a production incident, it can search OpenSearch for the application logs around the error, check Grafana for the matching metric anomaly, review recent GitHub activity to see what changed, and confirm deployment state in ArgoCD, all through one gateway and one auth boundary. Instead of a human stitching the story together, the agent gathers its own evidence.</p><p>This is also why the observability servers matter so much to us. Grafana and OpenSearch sit behind the proxy so that agents can verify their hypotheses against real telemetry rather than act on them blindly. And because AgentGateway was designed to observe agent traffic, we can watch the gateway itself: which agent called which tool, how often, and to what effect. Closing that loop is one of our next investments.</p><p><strong>Where We’re Headed</strong></p><p>The headline item is OAuth token exchange. Today the proxy acts with service-level credentials. We want per-user identity propagation, so that an agent acting on an engineer’s behalf carries that engineer’s scopes and authorization decisions are made about a real person rather than a shared role.</p><p>When we shipped the first version, we thought we were building a convenience. It turned out to be the foundation for Imagine Learning’s SDLC process. Betting on an open protocol meant the ecosystem did much of the work for us, and putting every tool behind one gateway gave us a single place to add capability, observe behavior, and enforce policy. The proxy became a platform, and the platform is how our agents reach everything.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91d91b3c604f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/scaling-model-context-protocol-from-a-proxy-to-an-agent-gateway-91d91b3c604f">Scaling Model Context Protocol: From a Proxy to an Agent Gateway</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Powerful AI Agents Quickly with Strands Agents SDK]]></title>
            <link>https://medium.com/imaginelearning/building-powerful-ai-agents-quickly-with-strands-agents-sdk-479c21a94237?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/479c21a94237</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[generative-ai-use-cases]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <dc:creator><![CDATA[Blake Romano]]></dc:creator>
            <pubDate>Mon, 22 Sep 2025 19:54:52 GMT</pubDate>
            <atom:updated>2025-09-22T19:54:22.400Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Harnessing Generative AI for Faster, Smarter, and More Efficient Workflows</em></strong></p><p>Generative AI is rapidly transforming the way we interact with technology, from chatbots assisting customers to innovative tools for educators and students. Its impact is not only about staying ahead of the curve — it’s about building software faster, cheaper, and easier, while delivering greater value to users. Whether you’re focused on retaining customers, helping students, or streamlining development, integrating AI into your projects is essential for modern software development.</p><h3>Understanding AI Agents and Their Importance</h3><p>In AI, an “agent” is an autonomous system that perceives its environment, reasons, and takes actions to achieve specific goals. These agents power many contemporary AI applications, automating repetitive tasks, responding to user queries, orchestrating workflows, and making decisions with minimal human input. Their versatility makes them central to creating smarter, more responsive technology solutions.</p><h3>Strands Agents SDK: Your Toolkit for AI Agents</h3><p>AWS’ Strands Agents SDK is an open-source framework designed to simplify the process of building, deploying, and managing AI agents and agentic workflows. Supporting a wide variety of large language models (LLMs) and providers — including AWS Bedrock, Anthropic, Llama, OpenAI, and more — the SDK offers unmatched flexibility and scalability. With Strands Agents SDK, you can mix and match models to fit your unique needs and leverage generative AI efficiently with clear, easy-to-read code.</p><p><strong>Key Benefits of Strands Agents SDK</strong></p><ul><li><strong>Rapid Prototyping:</strong> Bring your ideas to life in minutes with minimal code needed!</li><li><strong>Open Source and Extensible:</strong> Easily build AI agents in a vendor-agnostic format and extend it for more advanced use cases.</li><li><strong>Model Provider Agnostic:</strong> Choose the best LLM for your application, whether it’s through AWS, OpenAI, Anthropic, etc.</li><li><strong>Open Source Protocols:</strong> Native support for Model Context Protocol (MCP) and Agent to Agent (A2A) protocol accelerates development.</li><li><strong>Deploy Anywhere:</strong> Strands Agents can run on any compute environment, including Bedrock AgentCore, Kubernetes, AWS Lambda, and more!</li></ul><h3>Getting Started: What You Need</h3><p>To begin, ensure you have:</p><ul><li>Basic Python programming knowledge</li><li>Credentials for your LLM provider (this example uses AWS Bedrock)</li><li>Access to a terminal and your preferred code editor</li></ul><h3>Step-by-Step: Build a Terminal-Based Math Tutor for K-12 Students</h3><h4>Step 1: Install Strands Agents SDK</h4><p>Install the SDK via your terminal:</p><pre>pip install strands-agents-sdk strands-agents-tools</pre><h4>Step 2: Import Required Modules</h4><p>Import the essential modules to set up your agent:</p><pre>from strands import Agent<br>from strands.models.bedrock import BedrockModel<br>from strands_tools import calculator, handoff_to_user</pre><p>In this case we are going to import the core Agent class from Strands as well as the BedrockModel class to configure our model provider and add two tools from the Strands Tools library which will be a calculator and a hand off to user.</p><h4>Step 3: Create a System Prompt for Guided Learning</h4><p>Shape your agent’s behavior by configuring a system prompt. For guided learning, the prompt should instruct the agent to help students work through problems, ask questions, and avoid giving direct answers.</p><pre>system_prompt = &quot;&quot;&quot;<br>You are a helpful math tutor for K-12 students. <br>Use the calculator tool to help with math problems. <br>Do not give the student the answer directly but try to guide them through the problem.<br>Hand off to the user for clarification or if you want them to do the calculation themselves.<br>&quot;&quot;&quot;</pre><h4>Step 4: Initialize the Agent with Tools</h4><p>Set up your agent, specifying the model from AWS Bedrock (e.g., “us.anthropic.claude-sonnet-4–20250514-v1:0”), name, description, and adding the calculator and handoff tools.</p><pre>provider = BedrockModel(<br>  region_name=&quot;us-east-1&quot;,<br>  model_id=&quot;us.anthropic.claude-sonnet-4–20250514-v1:0&quot;,<br>  streaming=True,<br>)<br>agent = Agent(<br>  tools=[calculator, handoff_to_user],<br>  model=provider,<br>  system_prompt=system_prompt<br>)</pre><p>The <strong>calculator tool</strong> lets your agent perform calculations, while the <strong>handoff to user tool</strong> enables prompting the student to solve or clarify steps themselves.</p><h4>Step 5: Interact with the Agent via Terminal</h4><p>Use a simple loop to interact with your math tutor agent:</p><pre>while True:<br>  question = input(&quot;Ask a math question (or type &#39;exit&#39; to quit): &quot;)<br>  if question.lower() == &#39;exit&#39;: break<br>  response = agent.ask(question)<br>  print(response)</pre><p>Now, students can type math problems and receive hints, guiding questions, or partial steps from the agent.</p><p>The full code can be seen below:</p><pre>from strands import Agent<br>from strands.models.bedrock import BedrockModel<br>from strands_tools import calculator, handoff_to_user<br><br>system_prompt = &quot;&quot;&quot;<br>You are a helpful math tutor for K-12 students. <br>Use the calculator tool to help with math problems. <br>Do not give the student the answer directly but try to guide them through the problem. <br>Hand off to the user for clarification or if you want them to do the calculation themselves. <br>&quot;&quot;&quot;<br><br>provider = BedrockModel(<br>  region_name=&quot;us-east-1&quot;,<br>  model_id=&quot;us.anthropic.claude-sonnet-4-20250514-v1:0&quot;,<br>  streaming=True,<br>)<br><br>agent = Agent(<br>  tools=[calculator, handoff_to_user],<br>  model=provider,<br>  system_prompt=system_prompt<br>)<br><br>while True:<br>  question = input(&quot;Ask a math question (or type &#39;exit&#39; to quit): &quot;)<br>  if question.lower() == &#39;exit&#39;: break<br>  response = agent(question)<br>  print(response)</pre><p>The system prompt ensures that the agent acts as a coach — asking guiding questions, pointing out errors, and encouraging students to try calculations themselves. If a student is stuck or needs clarification, the agent uses the handoff tool to let them take the lead or prompt them to perform the next step.</p><ul><li><strong>Guided Tutoring:</strong> Promotes understanding by breaking problems into steps and checking comprehension.</li><li><strong>Handoff Tool:</strong> Empowers students to try calculations, reinforcing active learning and problem-solving skills.</li></ul><h4>Next Steps and Customization</h4><p>With the example above, you can create a terminal-based math tutor in just around 25 lines of code that helps students build confidence and mathematical skills. The Strands Agents SDK enables easy customization — add new tools, refine prompts for different math topics, or deploy your agent and integrate it into your application. With just a few lines of code, you’re supporting students through guided discovery and AI-powered learning.</p><h3><strong>Best Practices and Tips</strong></h3><ul><li><strong>Experiment with Different Models:</strong> Test multiple LLM providers to see which works best for your needs. Consider cost, latency, and accuracy.</li><li><strong>Start Simple:</strong> Begin with a basic agent and add features as you go.</li><li><strong>Monitor and Iterate:</strong> Track agent performance and adjust based on user feedback.</li><li><strong>Respect User Privacy:</strong> Always be mindful of the data your agents handle. Leverage things like guardrails to protect users.</li></ul><h3>Conclusion</h3><p>The Strands Agents SDK from AWS is a powerful solution for building AI agents and workflows quickly and efficiently. By supporting a wide range of LLMs and lowering the development barrier, it enables developers, educators, and businesses to innovate and automate like never before. Ready to add generative AI to your products or processes? Give the Strands Agents SDK a try — you might be surprised by how much you can accomplish with just a few lines of code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=479c21a94237" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/building-powerful-ai-agents-quickly-with-strands-agents-sdk-479c21a94237">Building Powerful AI Agents Quickly with Strands Agents SDK</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Case for Vibe Coding]]></title>
            <link>https://medium.com/imaginelearning/a-case-for-vibe-coding-f23a69648670?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/f23a69648670</guid>
            <category><![CDATA[vibe-coding]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[design-process]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Paul Palladino]]></dc:creator>
            <pubDate>Mon, 22 Sep 2025 18:20:31 GMT</pubDate>
            <atom:updated>2025-09-22T18:20:13.650Z</atom:updated>
            <content:encoded><![CDATA[<h3>AI Bridging Disciplines: How Vibe Coding is Actually the Missing Link We Need</h3><p>Software engineers sneer at “vibe coding,” and for good reason. We have spent our careers battling tech debt-laden codebases, fielding after-hours production incidents, fighting to get refactoring of unmaintainable code onto roadmaps, and enduring hundreds of other unpleasant realities that stem from hastily written code. I get it. We all know that Mark Zuckerberg announcing that 50% of Meta’s code will be AI-generated by 2026 is complete baloney, and watching board members demanding the same of their organizations is wreaking havoc in workplaces everywhere.</p><p>But here’s the thing: I think we’re seeing a hole where there’s actually a donut, and our justified skepticism about AI-generated production code might be blinding us to something genuinely helpful.</p><p>You know that famous illustration…the one with the tire swing that perfectly captures the beautiful disaster of software development? The customer explains what they want (a rope swing with three tiers), the project leader understands something completely different (swing blocked by the tree), the analyst designs yet another interpretation (tree supported by other trees), and by the time it reaches the programmer, we’ve somehow built a complex system that nobody asked for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*5_kS154ghsGBDIgeDt8zvA.jpeg" /></figure><p>We’ve laughed at this comic for years, shrugged our shoulders, and accepted it as “just how software development works.” But what if it doesn’t have to be? What if our knee-jerk dismissal of AI-powered prototyping is causing us to miss a solution we’ve been waiting for?</p><h3>Enter the AI-Powered Prototype</h3><p>Here’s where we need to set aside our preconceptions and look at what’s actually happening. When subject matter experts and stakeholders start “vibe coding” with AI tools, they’re not trying to ship production software…and that’s exactly the breakthrough we’ve been missing.</p><p>Think about it without the defensive reflexes for a moment. Instead of writing a 50-page requirements document that somehow still leaves room for catastrophic misinterpretation, a non-technical subject matter expert can now sit down with Claude Code or CoPilot and actually build a working prototype of what they have in mind. Yes, it might be held together with digital duct tape, but it <em>works</em>. Users can click it, poke it, and most importantly, break it in ways that reveal the true requirements.</p><h3>Shrinking The Feedback Loop</h3><p>This is the paradigm shift we need to embrace, not resist. Instead of:</p><p><strong>Traditional Flow (The Broken Telephone Game):</strong> Stakeholder idea → Requirements doc → UX mockups → Engineering estimates → Development → “This isn’t what we wanted” → Costly rework cycle</p><p>We get:</p><p><strong>AI-Assisted Flow:</strong> Stakeholder idea → AI-powered prototype → Stakeholder refinement → User testing → Validated concept → UX/Engineering handoff with actual user feedback</p><p>Stop and really absorb what this means. The magic isn’t in the code quality…it’s in eliminating the guesswork. When stakeholders can iterate on a working prototype themselves, they discover what they actually want versus what they thought they wanted. They catch the gotchas, the edge cases, the “oh wait, this user flow is completely backwards” moments…all before we write a single line of production code.</p><h3>Quality Where It Matters</h3><p>Now, before you roll your eyes and think “but the code quality!”…stop. Take a breath. Let go of that perfectionist instinct for just a moment.</p><p>These AI-generated prototypes are not production-ready, they’re the software equivalent of a concept car: impressive enough to test drive, functional enough to reveal flaws, but nobody’s confused about whether they belong on the road.</p><p>The real breakthrough isn’t in the code quality; it’s in the <strong>clarity of intent</strong>. When a product manager hands off a working prototype to the engineering team, complete with user test results and battle-tested requirements, everything changes. The conversation shifts from “I think users want this” to “Users tested this exact interaction 47 times and here’s the data on what worked and what failed spectacularly.”</p><h3>The New Development Handoff</h3><p>This is a valuable process evolution disguised as messy prototyping. Subject matter experts become empowered to explore and validate ideas at the speed of thought, while engineers can focus entirely on what they do best: building robust, scalable, maintainable solutions. UX designers get to work with validated concepts instead of playing requirements archaeology.</p><p>The tire swing problem doesn’t disappear entirely, but it transforms from a systemic failure into a solvable calibration issue. When everyone can see, touch, and break the same working prototype, we’re all finally looking at the same swing. The gap between disciplines doesn’t just narrow…it becomes a bridge.</p><h3>Looking Forward</h3><p>We’re standing at an inflection point, and our response will define the next decade of software development. AI isn’t replacing software engineers…it’s making everyone else more fluent in our language. It’s giving stakeholders a way to express their ideas in working code rather than imperfect words.</p><p>The choice is ours: we can keep snickering at “vibe coding” and maintain our professional superiority, or we can recognize this for what it really is…a universal translator we’ve desperately needed for years.</p><p>So here’s my challenge: the next time someone shows you their “vibe coded” prototype, resist the urge to critique the code quality. Instead, ask yourself: “What if this messy, imperfect thing is actually the missing piece we’ve been searching for?”</p><p>The future of product development isn’t about perfect code from day one…it’s about perfect understanding before line one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*zQuTB_XEbpXGu9vP8ynoyA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f23a69648670" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/a-case-for-vibe-coding-f23a69648670">A Case for Vibe Coding</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking Developer Efficiency with Model Context Protocol (MCP)]]></title>
            <link>https://medium.com/imaginelearning/unlocking-developer-efficiency-with-model-context-protocol-mcp-fd03e9831d3d?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/fd03e9831d3d</guid>
            <category><![CDATA[model-context-protocol]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[generative-ai-use-cases]]></category>
            <dc:creator><![CDATA[Blake Romano]]></dc:creator>
            <pubDate>Wed, 16 Jul 2025 00:06:56 GMT</pubDate>
            <atom:updated>2025-07-16T00:06:56.743Z</atom:updated>
            <content:encoded><![CDATA[<p>At <a href="https://www.imaginelearning.com/">Imagine Learning</a>, we’ve invested heavily in building tools that support our developers across every stage of the software development lifecycle. But as those tools grew in number, spanning services like AWS, ArgoCD, Jira, Confluence, and more, we began noticing a familiar pattern. Engineers were spending too much time searching for answers and not enough time building software.</p><p>Support channels were filled with questions that documentation already answers. Developers paused their work to hunt through internal documentation to retrieve information. The tools existed, but we didn’t have a cohesive experience to use them, and it was costing our engineers time and focus.</p><p>We needed a better way to unify access to the systems our developers rely on without asking them to hop between different documentations or install new interfaces. Instead of pulling developers into tools, we focused on delivering tools into their existing workflows.</p><h3><strong>Model Context Protocol</strong></h3><p>We turned to the <a href="https://modelcontextprotocol.io/introduction">Model Context Protocol (MCP)</a>, an open protocol designed to bridge the gap between large language models (LLMs) and external tools. MCP gives structure to how tools expose functionality by defining a shared contract for inputs, context, and interactions.</p><p>MCP gives us a reliable way to expose internal tools to AI systems without building custom integrations for each one. We can leverage open source MCP servers like <a href="https://github.com/awslabs/mcp">AWS’</a> in a way that makes it easy for us to integrate new services into our proxy without having to write the servers ourselves. Leveraging MCP makes it possible to build scalable, reliable integrations with minimal overhead.</p><p>Importantly, MCP makes it possible to connect directly to where developers are already working. With integrations into their IDEs like Visual Studio Code or IntelliJ, engineers don’t need to switch tools to get help. They are able stay in their editor, and the system can adapt to their context.</p><h3><strong>Making It Work in Practice</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nBQeNI9dpqdQoImxPgxduQ.png" /></figure><p>We built a containerized system that runs multiple MCP STDIO servers behind a single HTTP interface. Each MCP server handles one integration and is converted to Streamable HTTP servers using <a href="https://github.com/supercorp-ai/supergateway/">SuperGateway</a>, and <a href="https://nginx.org/">NGINX</a> routes requests based on the endpoint, allowing agents and developers to access tools without managing the software to run STDIO servers locally. Everything is packaged in a single Docker container, with no local setup required. This lightweight approach ensures the tools are usable even on low-powered developer machines or in browser-based IDEs. Access is internal-only, and the current setup supports read-only operations to maintain high security standards while still providing value.</p><h3><strong>The Impact on Developer Experience</strong></h3><p>Engineers can retrieve documentation, review deployment metadata, or check ticket history directly from their development environment. This allows for fewer interruptions, shorter onboarding times, and a more centralized access point for knowledge.</p><p>Platform teams’ benefit, too. With MCP, we are able to leverage open source MCP servers instead of having to develop each one ourselves. As a result, we only need to maintain one proxy instead of many different sets of containers. From there, the proxy can be accessed programmatically by agents, queried by developers, or embedded into different interfaces without having to rebuild the same logic across interfaces.</p><h3><strong>Where We’re Headed</strong></h3><p>This work is still evolving. We’re exploring how to extend access control, improve observability for agent usage, and expand support to additional tools. For now, read-only access ensures that we maintain strong security boundaries while laying the groundwork for more advanced capabilities.</p><p>MCP has helped us simplify access to internal knowledge and services, reduce support overhead, and improve developer focus. It’s a straightforward pattern that scales well, integrates cleanly, and enhances the way our teams build.</p><p><a href="https://www.linkedin.com/in/blakeromano/"><em>Blake Romano</em></a><em>, Senior Software Engineer</em></p><p><a href="https://www.linkedin.com/in/mason-price-ab4553282/"><em>Mason Price</em></a><em>, Associate Software Engineer</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd03e9831d3d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/unlocking-developer-efficiency-with-model-context-protocol-mcp-fd03e9831d3d">Unlocking Developer Efficiency with Model Context Protocol (MCP)</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI Powered Search — Hello World]]></title>
            <link>https://medium.com/imaginelearning/ai-powered-search-hello-world-02313b38a52e?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/02313b38a52e</guid>
            <category><![CDATA[hello-world]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[text-embedding]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Paul Palladino]]></dc:creator>
            <pubDate>Wed, 12 Feb 2025 18:51:29 GMT</pubDate>
            <atom:updated>2025-02-12T18:51:29.263Z</atom:updated>
            <content:encoded><![CDATA[<h3>AI Powered Search — Hello World</h3><p>Recently, several engineering friends and colleagues have shown interest in experimenting with AI features within their applications. I’ve shared code and guided them through the process, but I realized that creating a “Hello World”–style project could be beneficial for others looking to learn. In this article, I’ll walk you through building a simple AI-powered semantic search, providing both the code and the necessary background to get you started. So, let’s dive in!</p><p>Find a complete project example on my <a href="https://github.com/ppalladino/ai-powered-search-hello-world">github</a>.</p><h4>What We Will Cover</h4><p>In this project, we’ll create a basic AI-powered semantic search by following these steps:</p><ul><li>We will cover what a text embedding, a key concept, is and how to use it</li><li>We will set up an account with OpenAI and get an API key. This cost $5 but is the simplest way to get started.</li><li>We will start with a small data set containing 100 popular movies and their descriptions.</li><li>We will create a function that takes in a search term, and return the best semantic match from our sample data set</li></ul><h4>1. Key Concept: What is a text embedding?</h4><p><strong>Think of text embeddings as a way to translate words and sentences into numbers that computers can understand.</strong></p><p>Imagine you have a sentence like “I love pizza.” While humans easily grasp its meaning, computers need a different approach to work with it. Here’s how text embeddings help:</p><ol><li><strong>Conversion to Numbers:</strong> Text embeddings take each word or the entire sentence and convert it into a series of numbers. For example, “I love pizza” might become something like [0.5, 1.2, -0.7].</li><li><strong>Capturing Meaning:</strong> These numbers aren’t random. They are crafted in a way that captures the meaning and context of the words. So, sentences with similar meanings will have similar number representations. For instance, “I enjoy pizza” might have a similar numerical representation to “I love pizza.”</li><li><strong>Helping Computers Understand Relationships:</strong> By turning text into numbers, computers can easily compare different pieces of text, find patterns, and perform tasks like searching, translating, or answering questions.</li><li><strong>Comparing Text Embeddings:</strong> Comparing text embeddings involves measuring how similar or different two sets of numerical representations of text are. Since each text (like a word, sentence, or paragraph) is transformed into a vector of numbers, we can use mathematical techniques to assess their relationship. One common method is <strong>cosine similarity</strong>, which calculates the angle between two vectors; a smaller angle means the texts are more similar. Another method is <strong>Euclidean distance</strong>, which measures the straight-line distance between two points in the numerical space. By comparing these embeddings, computers can determine how closely related the meanings of different texts are, enabling tasks like finding similar documents, clustering related topics, or improving search accuracy. Essentially, comparing text embeddings allows machines to understand and evaluate the semantic relationships between pieces of text in a meaningful, quantitative way.</li></ol><h4>Set up a python project and grab sample data</h4><ul><li>Create a new directory somewhere to put your code</li><li>In it, create a <strong>requirements.txt</strong> file to put dependencies in:</li></ul><pre>python-dotenv==1.0.1<br>openai==1.61.1<br>pandas==2.2.3<br>scikit-learn==1.6.1<br>rich==13.9.4<br>tqdm==4.67.1</pre><ul><li>Create an <strong>install.sh</strong> which will create a virtual python environment so you don’t override your machine’s existing python packages and creates a local environment file to put your API key in. Don’t commit your environment file! You don’t want to leak your new API key do you?</li></ul><pre>#!/bin/bash<br><br># Create and activate virtual environment<br>python3 -m venv venv<br>source ./venv/bin/activate<br><br># Upgrades package manager and installs dependencies<br>pip install --upgrade pip<br>pip install -r requirements.txt<br><br># Creates a local .env file and adds a variable for your API key<br>touch .env<br>grep -qF &#39;OPENAI_API_KEY&#39; .env || echo &#39;OPENAI_API_KEY=&#39; &gt;&gt; .env<br><br># Done!<br>echo &quot;Install...done.&quot;</pre><ul><li>Open a terminal in your project directory, then update permissions on your <strong>install.sh</strong> script and run it.</li></ul><pre>&gt; chmod +x install.sh<br>&gt; ./install.sh</pre><ul><li>Set up an account with OpenAI and get an API Key. First navigate to <a href="https://platform.openai.com/docs/overview">https://platform.openai.com/docs/overview</a> and create an account with OpenAI. Again, there are alternatives to OpenAPI and you can even have an LLM locally, but this is a “Hello World” so trying to keep things simple.</li><li>Navigate to <a href="https://platform.openai.com/api-keys">https://platform.openai.com/api-keys</a> and create an API key and add it to the <strong>.env</strong> file created by the <em>install.sh</em> script above.</li></ul><pre>OPENAI_API_KEY=&lt;YOUR OPENI KEY&gt;</pre><ul><li>Next grab sample data from the example github repo: <a href="https://github.com/ppalladino/ai-powered-search-hello-world/blob/main/search_data.csv">search_data.csv</a> and put in the root of your project directory.</li><li>Create a <strong>lib.py</strong> file in root of the project and add the code below. Check out the comments for details on each. There are four functions that: reads the api key from the .env file, requests text embeddings from OpenAI, appends text embeddings to the search data .csv, and finally finds similar search data items for a given search term.</li></ul><pre># lib.py<br><br>import os<br>from dotenv import load_dotenv<br>from openai import OpenAI<br>import ast<br>import pandas as pd<br>import numpy as np<br>from sklearn.metrics.pairwise import cosine_similarity<br>from tqdm import tqdm<br>from rich.console import Console<br>from rich.table import Table<br><br># This is only for displaying a progress bar. Just a nice to have.<br>tqdm.pandas()<br><br>def get_api_key() -&gt; str:<br>    # Get the api key from the .env file<br>    load_dotenv(override=True)<br>    api_key = os.getenv(&#39;OPENAI_API_KEY&#39;)    <br>    return api_key<br><br>def request_text_embedding(text: str, api_key: str) -&gt; list:<br>    # Request a text embedding from OpenAI for the given text<br>    client = OpenAI(api_key=api_key)<br>    response = client.embeddings.create(<br>        input=text,<br>        model=&quot;text-embedding-ada-002&quot;<br>    )<br>    return response.data[0].embedding<br><br>def append_text_embeddings_to_search_data():<br>    # Read in the sample data<br>    df = pd.read_csv(&quot;search_data.csv&quot;)<br><br>    # Read in the api key from the .env file<br>    api_key = get_api_key()<br><br>    # Request a text embedding from OpenAI for each row&#39;s overview value <br>    # and append it as a new column &#39;overview_text_embedding&#39;<br>    df[&quot;overview_text_embedding&quot;] = df[&quot;overview&quot;].progress_apply(<br>        lambda text: request_text_embedding(text, api_key)<br>    )<br><br>    # Save the a new CSV file with the updated data<br>    df.to_csv(&quot;search_data_with_embeddings.csv&quot;, index=False)<br><br>def find_similar_matches(search_term: str, show_n: int = 1):<br>    df = pd.read_csv(&quot;search_data_with_embeddings.csv&quot;)<br><br>    # Convert the &#39;overview_text_embedding&#39; from string representation to actual lists<br>    df[&#39;overview_text_embedding&#39;] = df[&#39;overview_text_embedding&#39;].apply(ast.literal_eval)<br>    <br>    api_key = get_api_key()<br>    <br>    # Obtain embedding for the search term<br>    search_term_text_embedding = request_text_embedding(search_term, api_key)<br>    <br>    # Convert embeddings to numpy arrays for efficient similarity computation<br>    search_data_text_embeddings = np.array(df[&#39;overview_text_embedding&#39;].tolist())<br>    search_term_text_embedding = np.array(search_term_text_embedding).reshape(1, -1)<br>    <br>    # Here is where the magic happens. We compute the cosine similarity of the search <br>    # term embedding and the search data. In &quot;real life&quot; you would probably want to <br>    # query a vector capable database for large datasets, but this is a simple <br>    # &quot;hello world&quot; example :)<br>    similarities = cosine_similarity(search_term_text_embedding, search_data_text_embeddings)[0]<br>    <br>    # Add similarity scores to the DataFrame<br>    df[&#39;similarity&#39;] = similarities<br>    <br>    # Sort search data by similarity in descending order and select the top N<br>    df_sorted_by_similarity = df.sort_values(by=&#39;similarity&#39;, ascending=False).head(show_n)<br><br>    return df_sorted_by_similarity</pre><ul><li>Next, create a <strong>main.py</strong> file in the project root. This will be the script that you will execute via your terminal to take a search term and display results. It also creates a new .csv with search data text embeddings if it doesn’t already exist. It take a little time to generate this, but is need only once.</li></ul><pre># main.py <br><br>import argparse<br>import sys<br>import os<br>import lib<br>from rich.console import Console<br>from rich.table import Table<br><br>def main():<br>    # Parse the command line arguments<br>    parser = argparse.ArgumentParser(description=&#39;Find the best matches for a given search term.&#39;)<br>    parser.add_argument(&#39;search_term&#39;, type=str, help=&#39;The search term to find matches for.&#39;)<br>    parser.add_argument(&#39;--top_n&#39;, type=int, default=1, help=&#39;Number of top matches to display (default: 1).&#39;)<br>    args = parser.parse_args()<br>    <br>    # Check if the &quot;search_data_with_embeddings.csv&quot; file exists and if not, create it<br>    # This will take some time, but will only be required once<br>    search_data_embeddings_file = &quot;search_data_with_embeddings.csv&quot;<br>    if not os.path.exists(search_data_embeddings_file):<br>        print(&quot;Generating embeddings for serch data. This may take a while...but is needed only once.&quot;)<br>        lib.append_text_embeddings_to_search_data()<br>        print(f&quot;Embeddings generated and saved to &#39;{search_data_embeddings_file}&#39;.&quot;)<br>    <br>    # Find similar matches for the search term<br>    similar_matches = lib.find_similar_matches(args.search_term, args.top_n)<br><br>    # Display results in a rich table. This is a nice to have for readable results.<br>    console = Console()<br>    table = Table(<br>        title=f&quot;Top {args.top_n} Semantic Search Results for: &#39;{args.search_term}&#39;&quot;,<br>        show_lines=True<br>    )<br><br>    table.add_column(&quot;Similarity Score&quot;, justify=&quot;left&quot;, style=&quot;green&quot;)<br>    table.add_column(&quot;Title&quot;, justify=&quot;right&quot;, style=&quot;cyan&quot;, no_wrap=True)<br>    table.add_column(&quot;Overview&quot;, justify=&quot;left&quot;, style=&quot;magenta&quot;)<br><br>    for _, row in similar_matches.iterrows():<br>        table.add_row(f&quot;{row[&#39;similarity&#39;]:.3f}&quot;, row[&#39;title&#39;], row[&#39;overview&#39;])<br><br>    console.print(table)<br><br>if __name__ == &#39;__main__&#39;:<br>    main()</pre><ul><li>Finally, lets give this whirl! In your terminal execute the <strong>main.py</strong> file and pass in a search term and an optional argument for the number of results to be displayed. Remember, if this is the first time running this, there is a one time wait period while the search data text embeddings are requested.</li></ul><pre>&gt; python main.py &quot;adventure heroes&quot; --top_n 3</pre><ul><li>If all goes well you will see the most similar search results displayed. Enjoy!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6DVcr5jax1zUwQUoNh0Prg.png" /></figure><ul><li>Given that this example uses <strong>venv </strong>to protect your existing python packages, when starting a new terminal session, execute the below command in your <strong>terminal</strong> to start the python virtual environment</li></ul><pre>&gt; source venv/bin/activate</pre><h4>Final Thoughts</h4><ul><li>You can find complete code example on github: <a href="https://github.com/ppalladino/ai-powered-search-hello-world">https://github.com/ppalladino/ai-powered-search-hello-world</a></li><li>This is only a “Hello World” example for learning purposes. I omitted defensive code and exception handling for brevity. Also, there are better and more efficient methods for AI powered search, perhaps I’ll cover that in a future article.</li><li>If you have any issues, or suggestions for making this example better, I invite you to submit a bug to the github repository linked above.</li><li>Thank you for time reading this, I hope it was interesting!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02313b38a52e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/ai-powered-search-hello-world-02313b38a52e">AI Powered Search — Hello World</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generative AI Meets Internal Developer Platforms: Unleashing AWS Bedrock for Developer Efficiency —…]]></title>
            <link>https://medium.com/imaginelearning/generative-ai-meets-internal-developer-platforms-unleashing-aws-bedrock-for-developer-efficiency-01122fcfbc57?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/01122fcfbc57</guid>
            <category><![CDATA[bedrock]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Blake Romano]]></dc:creator>
            <pubDate>Thu, 06 Feb 2025 17:46:32 GMT</pubDate>
            <atom:updated>2025-02-06T17:46:32.893Z</atom:updated>
            <content:encoded><![CDATA[<h3>Generative AI Meets Internal Developer Platforms: Unleashing AWS Bedrock for Developer Efficiency — Part One</h3><p><em>How a small team is using AI to reclaim time to maintain and enhance the internal developer platform without sacrificing exceptional support for developers.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dyw43OSvfEHTsVHcfuR-Tg.jpeg" /></figure><p>After building the next-gen internal developer platform (IDP) for Imagine Learning, the excitement our team felt as we saw wider adoption was tempered as we began fielding questions on the support channel: “Hello team! I’m trying to deploy to the staging environment, but the build failed, and I couldn’t find any other error message. Can you guys help debug this failed build please?”</p><p>At first it was easy to dive in and engage with our IDP’s new users. However, as more users engaged with the platform, the number of questions increased, and we started seeing repeats of questions we had answered previously. Our team then had questions of our own: “Doesn’t anyone read the documentation?” How can we answer all these questions and still find time to develop the platform?” “How can we enhance the developer experience?”</p><p>Enter Artificial Intelligence (AI) — a transformative force in modern software creation. AWS Bedrock, Amazon’s fully managed service for Generative AI, provides a powerful way to embed Generative AI capabilities into an Internal Developer Platform (IDP), enabling faster, smarter, and more efficient developer workflows.</p><p>With AWS Bedrock, developers at Imagine Learning can access pre-trained, scalable AI models that integrate seamlessly with existing workflows, reducing the amount of time they need to spend searching through documentation.</p><p>The AWS Bedrock Agents, using retrieval-augmented generation (RAG), empowers our development teams to focus on what truly matters — building and shipping great software. Below, we share how we implemented AWS Bedrock to support our software engineers.</p><h3>Step 1: Setting Up AWS Bedrock</h3><p>To begin integrating Generative AI into the IDP, first set up an AWS Bedrock Agent. While AWS Bedrock provides access to pre-trained foundation models, the real power comes from configuring an agent tailored to your development ecosystem, retrieving relevant information, and delivering actionable insights.</p><h4>Provisioning AWS Bedrock</h4><p>First, ensure you have access to the AWS Bedrock service, as it’s available only in specific AWS regions. Once access is confirmed:</p><ol><li><strong>Navigate to AWS Bedrock</strong>: Open the AWS Management Console and search for “Bedrock.”</li><li><strong>Explore Foundation Models</strong>: AWS Bedrock offers various models (e.g., Claude, Jurassic-2, Titan). Select a model that aligns with your organization’s needs. Generative AI models like Anthropic’s Claude are well-suited for processing large volumes of natural language data, making them ideal for retrieval tasks.</li><li><strong>Select an Embedding Model</strong>: Choose a model for vectorizing data, which will be stored in a vector database (like OpenSearch).</li></ol><p>After requesting access to these models, proceed with setting up the Bedrock Agent and Knowledge Base.</p><ol><li><strong>Set up the Bedrock Agent</strong>: In the Agents tab, create a new agent. Choose the model you accessed and define the agent’s role, such as “You are a support agent responsible for answering questions about our Internal Developer Platform using documentation.” Click “Save and Exit.”</li><li><strong>Test the Agent</strong>: Test the agent with a sample question like, “How do you create an S3 bucket in our platform?” If the response isn’t accurate, proceed to set up the Bedrock Knowledge Base.</li></ol><h3>Step 2: Configuring a Bedrock Knowledge Base</h3><p>For effective retrieval-augmented generation (RAG) with AWS Bedrock, establish a structured knowledge base as the main reference point for developers. In this setup, the knowledge base syncs with Confluence, a widely used documentation platform, allowing the Bedrock Agent to quickly search relevant content and answer developer questions.</p><ol><li><strong>Syncing Confluence with Bedrock</strong>: Use Confluence as the primary documentation source for your platform. Generate an API token in Confluence and store it in AWS Secrets Manager as a “username” and “password” for secure access.</li><li><strong>Create the Knowledge Base</strong>: In the AWS Console, go to the Knowledge Bases tab to create a new knowledge base. For the data source, select Confluence, enter the URL, choose “Basic Authentication,” and link the stored secret from AWS Secrets Manager.</li><li><strong>Vector Database Configuration</strong>: Select an embedding model and opt for AWS OpenSearch Serverless to create a vector database. OpenSearch is cost-effective and easy to manage, storing vectorized data from Confluence for quick retrieval.</li></ol><p>After syncing Confluence data with the knowledge base, attach it to the Bedrock Agent. When developers ask questions like, “How do you create an S3 bucket in our platform?” the agent pulls information from Confluence. When new information is added to Confluence, simply re-sync to keep the agent’s responses up to date.</p><h3>Step 3: Integrating the Agent as a Chatbot</h3><p>With the Bedrock Agent configured to answer developer questions, the next step is to make it easily accessible. Instead of requiring developers to log into the AWS Console, integrate the agent with Slack using AWS Chatbot, allowing developers to get answers in their existing workspace.</p><ol><li><strong>Setting Up AWS Chatbot with Slack</strong>: In the AWS Chatbot console, link your Slack workspace, add a channel (using the channel ID from Slack), and assign necessary permissions (e.g., AmazonBedrockFullAccess) to the agent.</li><li><strong>Adding the Agent to Slack</strong>: Add the AWS app to the Slack channel and type “@aws connector add idp-support AGENT-ARN” in the channel. Developers can now ask questions like, “@aws ask idp-support How do you create an S3 bucket in our platform?” directly in Slack. Follow-up questions, such as “@aws can you tell me how to configure a lifecycle policy?”, are answered contextually within the same thread.</li></ol><h3>Conclusion</h3><p>Integrating AWS Bedrock into an IDP is a powerful way to boost developer productivity with Generative AI. By setting up a Bedrock Agent and linking it to a Confluence-powered knowledge base, we created a responsive, intelligent support system that saves Imagine Learning developers time and effort. The retrieval-augmented generation (RAG) approach enables engineers to access precise, context-aware responses aligned with our organization’s specific infrastructure.</p><p>The combination of AWS Bedrock’s scalability, Confluence’s structured documentation, and seamless integrations like AWS Chatbot opens the door to a future where developers have AI-driven support within their everyday tools. With no code maintenance required from the platform team, valuable development time is freed up, allowing teams to focus on their core mission — building and delivering innovative software.</p><p>As this journey continues, refining the knowledge base and exploring further AI integrations will ensure that the IDP remains a cutting-edge tool for development teams.</p><p><em>In Part Two of this article, we’ll demonstrate how to implement a feedback loop using Slack messages and replies to improve the Bedrock model’s accuracy and reliability. This feedback loop enables the chatbot to deliver even more precise, effective responses, better tailored to developers’ specific needs.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01122fcfbc57" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/generative-ai-meets-internal-developer-platforms-unleashing-aws-bedrock-for-developer-efficiency-01122fcfbc57">Generative AI Meets Internal Developer Platforms: Unleashing AWS Bedrock for Developer Efficiency —…</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Imagine Learning uses Crossplane & Composition Functions]]></title>
            <link>https://medium.com/imaginelearning/how-imagine-learning-uses-crossplane-composition-functions-25532e577538?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/25532e577538</guid>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[crossplane]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[internaldeveloperplatform]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <dc:creator><![CDATA[Blake Romano]]></dc:creator>
            <pubDate>Fri, 09 Aug 2024 17:05:13 GMT</pubDate>
            <atom:updated>2024-08-09T17:05:13.295Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*UEWSZUhigiwmUGcTbjubug.png" /></figure><p>Since Crossplane Composition Functions were promoted to beta in Crossplane version 1.14, the community has been adopting the new system. Some in the community are leaning into using open-source Composition Functions like <a href="https://github.com/crossplane-contrib/function-patch-and-transform/">Patch and Transform</a> or <a href="https://github.com/crossplane-contrib/function-go-templating/">Go Templates</a>. However, we at Imagine Learning have been building our own Composition Functions due to the troubles we have had with patch and transform with complex compositions.</p><p><a href="https://imaginelearning.com/">Imagine Learning</a> empowers educators to inspire breakthrough moments in every student’s unique learning journey with digital-first, K-12 education solutions. We use Crossplane in our own internal developer platform (IDP) to deploy resources into Amazon Web Services (AWS). Building out abstractions through compositions with native patch and transform was common. Composition files for resources like AWS RDS Clusters regularly contained more than 1,000 lines of repetitive code. We also needed several compositions to be able to specify different instance counts because native patch and transform does not support conditionally rendering resources. This repetition and the large files made testing changes to the compositions nearly impossible and authoring compositions difficult.</p><h3>Implementing Composition Functions</h3><p>After the release of Crossplane 1.14, Imagine Learning moved the existing patch and transform compositions to Functions. As part of that effort, we had to determine if we wanted to use a monolithic Composition Function for all compositions or to have a unique Function for each composition. We chose a monolithic approach. The monolithic approach allows us to route dynamically to the rendering logic for a specific composition and results in significantly fewer idle workloads running in our cluster. Another win associated with this model is that we only need to manage one code base.</p><p>Composition Functions have opened a lot of doors-allowing us to make our control plane easier to test and to run locally and they have improved our ability to manage complex compositions. For example, the composition YAML file for an RDS Cluster composition in the patch and transform framework was about 1,000 lines of code for a single instance cluster and 1,250 lines for a two-instance cluster. Two compositions that looked almost identical to each other were required to support provisioning a different number of database instances. With Crossplane Functions we were able to reduce that to a simple for loop reducing complexity and repetitiveness.</p><p>Here is a code snippet showing how, in an RDS Cluster Composition, we can use a coding practice like a loop to keep code clean and simple:</p><pre>instanceCount, _ := oxr.Resource.GetInteger(&quot;spec.resourceConfig.instanceCount&quot;) <br>for i := int64(0); i &lt; instanceCount; i++ { <br>  desired[resource.Name(fmt.Sprintf(&quot;instance-%v&quot;, i))] = resource.NewDesiredComposed() <br>  GenerateInstanceResource(desired[resource.Name(fmt.Sprintf(&quot;instance-%v&quot;, i))], oxr, observed, tags, i) <br>}</pre><p>Running Crossplane functions locally with the crossplane beta render CLI command allows us to validate that the rendering of resources is correct before deploying to a Kubernetes cluster. The ability to unit test and eventually integration test our compositions saves us from errors caused by contracts breaking between what is expected in the Composite Resource (XR) or in EnvironmentConfigs and what we have deployed.</p><p>Here is the output from crossplane beta render command for an S3 Bucket Composition:</p><pre>apiVersion: imaginelearning.engineering/v1alpha1 <br>kind: XS3Bucket <br>metadata: <br>  labels: <br>    cluster: platform-production <br>    domain: platform <br>    product: sandbox <br>  managedFields: null <br>  name: sandbox-dev-sample-python-bucket-12easda <br>spec: <br>  claimRef: <br>    apiVersion: imaginelearning.engineering/v1alpha1 <br>    kind: S3Bucket <br>    name: sandbox-dev-sample-python-bucket <br>    namespace: sandbox-dev <br>  resourceConfig: {} <br>status: <br>  bucketArn: arn:aws:s3:::sandbox-dev-sample-python-bucket <br>  bucketName: sandbox-dev-sample-python-bucket <br>--- <br>apiVersion: s3.aws.upbound.io/v1beta1 <br>kind: BucketServerSideEncryptionConfiguration <br>metadata: <br>  annotations: <br>    crossplane.io/composition-resource-name: bucket-ses <br>  generateName: sandbox-dev-sample-python-bucket-12easda- <br>  labels: <br>    crossplane.io/claim-name: sandbox-dev-sample-python-bucket <br>    crossplane.io/claim-namespace: sandbox-dev <br>    crossplane.io/composite: sandbox-dev-sample-python-bucket-12easda <br>  managedFields: null <br>  name: sandbox-dev-sample-python-bucket <br>  ownerReferences: <br>  - apiVersion: imaginelearning.engineering/v1alpha1 <br>    blockOwnerDeletion: true <br>    controller: true <br>    kind: XS3Bucket <br>    name: sandbox-dev-sample-python-bucket-12easda <br>    uid: &quot;&quot; <br>spec: <br>  deletionPolicy: Orphan <br>  forProvider: <br>    bucketSelector: <br>      matchControllerRef: true <br>    region: us-east-2 <br>    rule: <br>    - applyServerSideEncryptionByDefault: <br>      - sseAlgorithm: AES256 <br>  providerConfigRef: <br>    name: aws-provider <br>--- <br>apiVersion: s3.aws.upbound.io/v1beta1 <br>kind: Bucket <br>metadata: <br>  annotations: <br>    crossplane.io/composition-resource-name: bucket <br>  generateName: sandbox-dev-sample-python-bucket-12easda- <br>  labels: <br>    crossplane.io/claim-name: sandbox-dev-sample-python-bucket <br>    crossplane.io/claim-namespace: sandbox-dev <br>    crossplane.io/composite: sandbox-dev-sample-python-bucket-12easda <br>  managedFields: null <br>  name: sandbox-dev-sample-python-bucket <br>  ownerReferences: <br>  - apiVersion: imaginelearning.engineering/v1alpha1 <br>    blockOwnerDeletion: true <br>    controller: true <br>    kind: XS3Bucket <br>    name: sandbox-dev-sample-python-bucket-12easda <br>    uid: &quot;&quot; <br>spec:<br>  deletionPolicy: Orphan <br>  forProvider: <br>    region: us-east-2 <br>    tags: <br>      cluster: platform-production <br>      domain: platform <br>      env: dev <br>      name: sandbox-dev-sample-python-bucket <br>      namespace: sandbox-dev <br>      product: sandbox <br>  providerConfigRef: <br>    name: aws-provider</pre><h3>Conclusion</h3><p>Building your internal developer platform (IDP) control plane with Crossplane using Composition Functions allows you to build with confidence. Imagine Learning has leveraged Composition Functions to reduce bugs and the toil of maintaining thousands of lines of YAML configuration. Adding more resources to Composition Function coverage, evaluating how to automate day two operations, and having a more thorough end-to-end test suite with a local Kubernetes cluster are the next steps we will take to bring our internal developer platform to the next level.</p><p>Blake Romano is a Software Engineer at Imagine Learning who leads the Internal Developer Platform Team to build an Internal Developer Platform to serve hundreds of engineers.</p><p><em>Originally published at </em><a href="https://blog.crossplane.io/building-crossplane-composition-functions-to-empower-your-control-plane/"><em>https://blog.crossplane.io</em></a><em> on March 7, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25532e577538" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/how-imagine-learning-uses-crossplane-composition-functions-25532e577538">How Imagine Learning uses Crossplane &amp; Composition Functions</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a React Application: Part II]]></title>
            <link>https://medium.com/imaginelearning/building-a-react-application-part-ii-76b407607df8?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/76b407607df8</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[redux-observable]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <category><![CDATA[rxjs]]></category>
            <dc:creator><![CDATA[Eric Gibby]]></dc:creator>
            <pubDate>Thu, 30 Jul 2020 15:26:09 GMT</pubDate>
            <atom:updated>2020-07-30T15:26:09.393Z</atom:updated>
            <content:encoded><![CDATA[<p>In the <a href="https://medium.com/imaginelearning/building-a-react-application-ec8cbf6b8694">first part of this tutorial</a>, we built a basic React application with Create React App and covered some core concepts like components, hooks, and routing. With that knowledge under our belt, we’re ready to explore more advanced topics, like handling asynchronous calls to load data, managing global application state with <a href="https://redux.js.org/">Redux</a>, and moving business logic out of components and into actions, reducers, and epics. It’s about to get wiiiiiild!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FOCu7zWojqFA1W%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FOCu7zWojqFA1W%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdzVwdDFrMzEwaGVoaDJsc21hdnZ0NXU3cjRlaDNlbjNxdGM5NW1tZyZlcD12MV9naWZzX2dpZklkJmN0PWc%2FOCu7zWojqFA1W%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="239" frameborder="0" scrolling="no"><a href="https://medium.com/media/09c96314fb5fffff18805ce967b2518e/href">https://medium.com/media/09c96314fb5fffff18805ce967b2518e/href</a></iframe><p>As a refresher, below is a diagram of how a typical React application might be structured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sDG26VYaNBuSLQ_JTtbQPQ.png" /><figcaption>Anatomy of a React Application</figcaption></figure><p>The first part of this tutorial covered the basics for the “Presentation” layer of the application. In this tutorial, we’re going to delve into the “Business Logic” and “Data” layers. But don’t worry, it’s not as boring as it sounds.</p><p>To fully understand this tutorial, you’ll want to be familiar with the concepts covered in the previous tutorial.</p><h3>System requirements</h3><p>As before, to build this application, you’re going to need a recent version of Node.js installed. I recommend using a tool like Node Version Manager (nvm) which allows you to install different versions of Node in parallel and switch between them. There are versions of nvm for both <a href="https://github.com/nvm-sh/nvm#installing-and-updating">MacOS (or Linux)</a> and <a href="https://github.com/coreybutler/nvm-windows/releases">Windows</a>.</p><h3>Getting started</h3><p>We’re going to be building on the <a href="https://ericgibby.github.io/spider-app">Spider game</a> we started in the previous tutorial. If you haven’t already built the previous project and just want to jump in here, you can <a href="https://github.com/ericgibby/spider-app">grab the project code from GitHub</a> and checkout the part-2 branch. Make sure your dependencies are up-to-date, then fire up the development server.</p><pre>yarn install<br>yarn start</pre><h3>Fetching data from an API</h3><p>Up to this point, our application has been completely self-contained. In the real world though, you’re probably going to need to interact with a backend through some sort of RESTful API. So what would that look like in our Spider game?</p><p>How about we add some functionality to check whether or not the word/phrase entered by the user contains valid words? That seems like it could be useful. To accomplish this we’re going to use the <a href="https://dictionaryapi.com/products/api-collegiate-dictionary">Merriam-Webster Collegiate Dictionary API</a>. You’ll need an API key to access the API, which you can get if you <a href="https://dictionaryapi.com/register/index">sign up for a free account</a>.</p><p>Once you’ve gotten an API key, let’s create a service for making requests to the API. For those coming from the Angular world, you may think of a service as a class that encompasses some narrow, well-defined functionality. For our purposes though, let’s think of a service as a stateless module that encompasses some narrow, well-defined functionality. That probably sounds like pretty much the same thing. The difference is that our service does not maintain any internal state — it simply exports stateless functions.</p><p>Create a file at src/services/dictionaryApi.ts. This file will be straight TypeScript with no JSX, so we can use the .ts extension. We’re going to export a single lookupWord function, that uses the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch">Fetch API</a> to make an HTTP request to the API and return the response.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8362747bbd40ed883456e06d39faa60/href">https://medium.com/media/b8362747bbd40ed883456e06d39faa60/href</a></iframe><p>You’ll notice we used <a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await">async/</a><a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await">await</a>, which is really just syntactic sugar around <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promises</a>. You may have also noticed some weird, Node-like syntax to access some configuration from environment variables:</p><pre>const API_KEY = process.env.REACT_APP_DICTIONARY_API_KEY;<br>const BASE_URL = process.env.REACT_APP_DICTIONARY_API_URL;</pre><p>This is <a href="https://create-react-app.dev/docs/adding-custom-environment-variables">special functionality brought to you by React Scripts</a>. It allows you to access environment variables, defined on the command line or in a .env file in the root of your project. Any environment variable that is prefixed with REACT_APP_ can be accessed this way, as well as the NODE_ENV variable which is defined by default. But keep in mind that the values are injected into the code at build-time, not at runtime.</p><p>Create a .env file in the root directory of the project, so we can define our API base URL and key.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b962dea8a2f4718fd1138d84aef2c2d6/href">https://medium.com/media/b962dea8a2f4718fd1138d84aef2c2d6/href</a></iframe><p>Now that we have our service, we can use the lookupWord function in the handleSubmit function of our App component. Our approach will not be super sophisticated. Basically, we’ll split the text up into individual words and lookup each word independently. Here’s a sample of the JSON response from dictionaryapi.com, if we were looking up the word “car”:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90ba00d3a6ecdcdefa4ae44827a1c2b5/href">https://medium.com/media/90ba00d3a6ecdcdefa4ae44827a1c2b5/href</a></iframe><p>There’s a lot more data in the response than we’ll actually use. For our purposes, we just want to iterate over each entry in the array, and check if our word exists in thestems array defined in the meta object. That should do reasonably well at identifying valid words. And of course, we’ll want to store a flag in state letting us know if we find any invalid words.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/902cc65ac268206eba1dab1096eae6e3/href">https://medium.com/media/902cc65ac268206eba1dab1096eae6e3/href</a></iframe><p>If you’re thinking that seems like a lot of logic to stuff into an event handler, you’re absolutely right. And we’ll address that a little later. For now though, let’s update the PlayContainer component to take our new invalid value as a prop and display a warning message to the user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44c7c3c280c45143c083944880759274/href">https://medium.com/media/44c7c3c280c45143c083944880759274/href</a></iframe><p><em>You may have noticed we’re creating a lot of similar </em><em>divs with various messages. As an additional exercise, feel free to encapsulate this into a </em><em>Callout component.</em></p><p>And now that the PlayContainer can accept an invalid prop, let’s update our App component to pass the value to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/109f3d6f89a721c7c6e255374a91446a/href">https://medium.com/media/109f3d6f89a721c7c6e255374a91446a/href</a></iframe><p>And just like that, we’ve added another layer from our application diagram!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*v3pEKnWvgWgrK-NUlQuESA.png" /></figure><h3>Bring on Redux!</h3><p>So our application is working pretty well at this point. But you may have noticed that our components are starting to do an awful lot. As our application grows, that can start to make it unwieldy and hard to maintain. <a href="https://redux.js.org/">Redux</a> is a predictable state container that centralizes your application’s state and logic, helping you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. Centralizing state and logic sounds like exactly what we need!</p><p>The basic principles of Redux are simple, as explained in the <a href="https://redux.js.org/introduction/getting-started#create-a-react-redux-app">Redux documentation</a>:</p><blockquote><em>The whole state of your app is stored in an object tree inside a single </em>store<em>. The only way to change the state tree is to emit an </em>action<em>, an object describing what happened. To specify how the actions transform the state tree, you write pure </em>reducers<em>.</em></blockquote><blockquote><em>That’s it!</em></blockquote><p>So the gist of it is this: Redux provides a single store, which houses your application state as a plain old JavaScript object. The store also provides you with a dispatcher, that allows you to dispatch actions to update your state (similar to how events are fired from components). Dispatched actions are run through a reducer function, which takes the current state object and the action as parameters, and returns a new state object that has been updated with the data from the action.</p><p>There are lots of different ways people have chosen to organize their Redux code. For this example though, we’re going to use the <a href="https://github.com/erikras/ducks-modular-redux">Ducks Modular Redux Pattern</a>. In my opinion, this pattern makes navigating your Redux code much simpler, as it keeps everything you need for a specific module all in one place.</p><p>We’re also going to use <a href="https://redux-toolkit.js.org/">Redux Toolkit</a> library, which comes directly from the Redux team. It provides some useful, opinionated tools for efficient Redux development, helping you to focus on your application’s core logic without worrying about a bunch of boilerplate code.</p><p>Let’s go ahead and install Redux Toolkit. It will also install Redux and some other useful libraries.</p><pre>yarn add @reduxjs/toolkit</pre><p>And with that, we can create our first action and reducer! In a typical Redux application you’ll have multiple reducers, which get combined together to create a root reducer. Each reducer correlates to a key in your state object. This may be getting confusing, but stick with me and hopefully it will start to make sense.</p><p>You’ll want to divide your reducers up in a way that makes some organizational sense. Since we’re managing the global state for our UI, it might make sense to divide it up by route/view. If we take that approach, we could structure our global state object like this:</p><pre>{<br>    play: { },<br>    start: { }<br>}</pre><p>And then if we break down our /play route, we can identify what pieces of data we need for its state.</p><pre>{<br>    play: {<br>        text?: string;<br>        usedLetters: string[];<br>    },<br>    start: { }<br>}</pre><p>Let’s dig into it by creating a new file at src/redux/modules/play.ts. In that file we’re going to define a new setText action creator that we can use to dispatch an action to update the word/phrase to guess. An action is just an object with a type field to identify the action, and an optional payload, which can be any type you want. A traditional action creator is a simple function that returns an action object.</p><p>We’re also going to define our reducer function, which takes the current state and action as parameters, and returns the updated state object. This traditionally involves a switch statement that keys off of the action type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44ced84ad9df1e8cd66bcba79c4e58cb/href">https://medium.com/media/44ced84ad9df1e8cd66bcba79c4e58cb/href</a></iframe><p>As you may have noticed, that’s a fair amount of code to write just to set a single string value in our state object. This is where Redux Toolkit starts to shine. They provide some utility functions, like <a href="https://redux-toolkit.js.org/api/createAction">createAction</a> and <a href="https://redux-toolkit.js.org/api/createReducer">createReducer</a>, to cut down on the boilerplate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4edb8a8912cf5c88090fcbfd59a273ec/href">https://medium.com/media/4edb8a8912cf5c88090fcbfd59a273ec/href</a></iframe><p>Now doesn’t that look nicer? It also gives the added benefit of better type support in our reducer functions, because the compiler is able to infer the type of payload from the action. Yay!</p><p>It’s also worth mentioning that the createReducer function from Redux Toolkit uses <a href="https://github.com/immerjs/immer">immer</a> under the hood, which allows you to write reducers as if they were mutating the state directly while still maintaining pure reducer functions. So in our reducer function above, it would have been completely safe to write it this way (I just prefer the more deliberate syntax):</p><pre>builder.addCase(setText, (state, { payload: text }) =&gt; {<br>    state.text = text;<br>});</pre><p>With our first reducer in place, let’s move on to setting up our store. First we’ll want a root reducer to combine the reducers from each of our Redux modules. Right now we only have one module, but that’s OK because this is just a trivial example for learning purposes (or at least, that’s what I’ll keep telling myself). Create a file at src/redux/root.ts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/018f08c5c555f78b5759bd0516d95dcb/href">https://medium.com/media/018f08c5c555f78b5759bd0516d95dcb/href</a></iframe><p>Not much to see here. The usefulness of combineReducers is more obvious as your application grows and you add additional reducers. But for now, we’ve got the structure in place to support a growing application.</p><p>Next, let’s configure our store. Create a file at src/redux/configureStore.ts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/207139abcb49d6986e15a1eee4decdae/href">https://medium.com/media/207139abcb49d6986e15a1eee4decdae/href</a></iframe><p>Again, not much to see here. We’re passing a configuration object to the configureStore function that allows us to specify our root reducer. Later on we’ll do some additional stuff, like configure middleware — but let’s not get ahead of ourselves.</p><h3>So what now?</h3><p>OK. We’ve created our first action and reducer. We’ve configured our store. But how do we use it in our application? Redux is designed to work in any JavaScript application. We <em>could</em> interact directly with the store object we created, which exposes a dispatch function and a getState function. However, <a href="https://react-redux.js.org/">React Redux</a> makes integrating Redux into your React application much, much simpler.</p><p>Before we can use it, we’ll need to install it:</p><pre>yarn add react-redux</pre><pre># Add types for better TypeScript support</pre><pre>yarn add -D @types/react-redux</pre><p>React Redux has already done the work of tying state changes in your Redux store to React’s change detection cycle. To tap into this, we’ll need to wrap our App component with React Redux’sProvider component and pass our store to it. We can do that in our index.tsx file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0005efb73f9a69a6fc203e9530d9da46/href">https://medium.com/media/0005efb73f9a69a6fc203e9530d9da46/href</a></iframe><p>With our Provider in place, we can start interacting with our store from our components. Traditionally, this was done through a <a href="https://reactjs.org/docs/higher-order-components.html">higher-order component</a> (HOC) that you would create with the <a href="https://react-redux.js.org/api/connect">connect</a> function. The connect function allows you to provide mapping functions as parameters, that map state values and action dispatchers to the component’s props. That way, you’re interacting with the store via your component’s props.</p><p>For example, our App component would look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f78a34c1f706331eee6a767d256c3087/href">https://medium.com/media/f78a34c1f706331eee6a767d256c3087/href</a></iframe><p>However, with the introduction of <a href="https://reactjs.org/docs/hooks-intro.html">React Hooks</a>, the React Redux team added <a href="https://react-redux.js.org/api/hooks">their own custom hooks</a>. So now it’s possible to access any piece of global state inside your component with useSelector, and dispatch any action with useDispatch — no HOCs required. So with the hooks, our App component looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d48b1bccff87d7f4a2d55120959f7805/href">https://medium.com/media/d48b1bccff87d7f4a2d55120959f7805/href</a></iframe><h3>Let’s do this!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*fowqeLiQ-rcZYpeO6o5Kkw.jpeg" /></figure><p>Hopefully Redux is starting to make more sense now that you’ve seen it in action. At this point we’re ready to take all our application state and move it into our Redux store, right? Well, not exactly.</p><p>You want to be deliberate and pragmatic about what data goes into your Redux store. Keep in mind that every action that is dispatched will run through every reducer. Things like form data are not good candidates for Redux, because a controlled component is going to fire off a state change with each keystroke. The <a href="https://redux.js.org/faq/organizing-state/#do-i-have-to-put-all-my-state-into-redux-should-i-ever-use-reacts-setstate">Redux FAQs</a> outline some rules of thumb to help you determine what data belongs in Redux:</p><blockquote>Do other parts of the application care about this data?</blockquote><blockquote>Do you need to be able to create further derived data based on this original data?</blockquote><blockquote>Is the same data being used to drive multiple components?</blockquote><blockquote>Is there value to you in being able to restore this state to a given point in time (ie, time travel debugging)?</blockquote><blockquote>Do you want to cache the data (ie, use what’s in state if it’s already there instead of re-requesting it)?</blockquote><blockquote>Do you want to keep this data consistent while hot-reloading UI components (which may lose their internal state when swapped)?</blockquote><p>So with that in mind, let’s take a look at our application. In our PlayContainer component, there are a couple of easy candidates: usedLetters and maxIncorrect. First we’ll add the appropriate action creators and update our reducer:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f129d250bf903967fd16f6367d8d02f/href">https://medium.com/media/4f129d250bf903967fd16f6367d8d02f/href</a></iframe><p>Then use it in our PlayContainer component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15f55531125dcbd9a15991642ea2845c/href">https://medium.com/media/15f55531125dcbd9a15991642ea2845c/href</a></iframe><h3>Selectors and derived state</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*oe70zcXupA9P9ATL7y5TVw.jpeg" /></figure><p>Looking at our use of the useSelector hook, you’ve probably been able to figure out what a selector is in the context of Redux. It’s really just a function that takes the state object as a parameter, and selects the desired value from it.</p><p>Up to this point we’ve been using anonymous functions for simplicity’s sake, but that approach can be problematic as the application grows. Ideally, we don’t want our components to need to be aware of the shape of our state object. If down the road we decide to move some things around in our state object, we don’t want to have to touch each component that relies on that piece of state. So how do we fix that? Well, a selector module should do the trick.</p><p>Create a file at src/redux/selectors/play.ts. In this file, we’ll export functions to select the pieces of state we’re using so far.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b14dd944665ee4f5b128164625d2c40/href">https://medium.com/media/1b14dd944665ee4f5b128164625d2c40/href</a></iframe><p>Then we can update our App and PlayContainer components to use our shiny, new selectors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d85151ebb455c1c538265e19017c1f5/href">https://medium.com/media/5d85151ebb455c1c538265e19017c1f5/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fbc11172f92bf959b29e4966849a723/href">https://medium.com/media/5fbc11172f92bf959b29e4966849a723/href</a></iframe><p>So now we have selectors, and they provide value with some degree of future proofing our components. But you may still find yourself asking, “Are they really worth it?” Well, before you pass judgement, let’s talk about derived state.</p><p>Derived state refers to values that are computed from other values in state. As an example of this, we can look at the textLetters object in the PlayContainer component. It’s an object that maps the unique letters in our text, and is derived from the text value coming out of our Redux store. The same is true of our correctCount and incorrectCount values, which derive their values from the usedLetters array coming out of our Redux store, along with the previously derived textLetters object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e714ee7e051e493de591a9fe4ee8a1e/href">https://medium.com/media/9e714ee7e051e493de591a9fe4ee8a1e/href</a></iframe><p>There are a few different ways we can manage this kind of derived state. One option would be to leave it as-is. But that’s not very sharable across components. Another option would be to calculate the derived values in our reducer and store them in the state object. That’s definitely more sharable, but it can bloat our state object, and adds more overhead to our reducer. A third option is to create a selector function that uses your existing selectors to get the relevant pieces of state, then returns the derived value. That’s sharable, and doesn’t bloat our state object … but what about performance? Remember, selectors are called all the time as part of React’s change detection cycle to determine if any state values have changed. We certainly don’t want to perform those computations repeatedly — potentially tens or hundreds of times per second. But what if we take some inspiration from our original solution, using memoized functions? Well now we’re getting somewhere!</p><p>As luck would have it, a solution already exists. <a href="https://github.com/reduxjs/reselect">Reselect</a> is a simple library that provides the ability to create memoized selectors. And get this: it’s already included with Redux Toolkit!</p><p>The <a href="https://github.com/reduxjs/reselect#creating-a-memoized-selector">createSelector</a> function takes an array of selectors as its first argument, and passes the values from those selectors as arguments to a selector function. The resulting selector is memoized, so the function is only executed when one of the dependent selectors returns a new value. Neat, huh?</p><p>Let’s add some memoized selectors to our src/redux/selectors/play.ts file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc7d974c5ee767479fa5b33580bc71f3/href">https://medium.com/media/dc7d974c5ee767479fa5b33580bc71f3/href</a></iframe><p>And then update our PlayContainer component to use our new memoized selectors:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e25af084523aa1ee961623f635bbf3e/href">https://medium.com/media/1e25af084523aa1ee961623f635bbf3e/href</a></iframe><p>As you can see, the amount of logic in our component is decreasing drastically — which is a good thing.</p><p><em>As an additional exercise, create a memoized selector to get the current </em>step<em> value.</em></p><h3>Are you thunking what I’m thunking?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F91fEJqgdsnu4E%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F91fEJqgdsnu4E%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F91fEJqgdsnu4E%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="333" frameborder="0" scrolling="no"><a href="https://medium.com/media/665d75b6b34f2bbcd4383228ae23c12a/href">https://medium.com/media/665d75b6b34f2bbcd4383228ae23c12a/href</a></iframe><p>So now we have Redux working in our application. And we’ve reduced the computation of derived state in our components through selectors. But we’ve still got a lot going on in our components. That handleSubmit function in our App component is a prime candidate for simplification. But how can we move that logic into Redux? As you are aware, that function makes HTTP requests to the dictionary API. But one of the <a href="https://redux.js.org/introduction/three-principles#changes-are-made-with-pure-functions">Three Principles of Redux</a> states that “Changes are made with pure functions.” So how do we handle asynchronous code in Redux? One word (although it kind of sounds like two): <a href="https://redux.js.org/api/applymiddleware">middleware</a>.</p><p>Middleware is the suggested way to extend Redux with custom functionality. It allows you to tap into your store’s dispatch function, so you can interact with — and even modify — your actions before they reach your reducer. Any side-effects triggered from actions (such as HTTP requests) should be handled in middleware.</p><p>But writing middleware is complicated, isn’t it? Not when it already exists! And especially not when it’s already included with — and configured by — Redux Toolkit. The <a href="https://github.com/reduxjs/redux-thunk">Redux Thunk</a> middleware allows you to write action creators that return a function instead of an object. A <a href="https://daveceddia.com/what-is-a-thunk/">thunk</a> is just another name for a function that is returned by a function. In the case of Redux Thunk, the function returned by your action creator takes the dispatch and getState functions as parameters, which then allows you dispatch additional actions or access the current state object. The Redux Thunk middleware checks each action as it is dispatched and if the action is a function (a thunk), rather than an object, it will execute the function with the dispatch and getState functions from the store.</p><p>So how does that help with HTTP requests? We can dispatch an action to make the HTTP request. When the request completes, we dispatch another action with the result. Is that about as clear as mud? Well, let’s try adding it to our application and see if that brings any clarity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdc8d66e4e0528b3ffa5165eddd09d22/href">https://medium.com/media/bdc8d66e4e0528b3ffa5165eddd09d22/href</a></iframe><p>That may seem like a lot to take in, but let’s break it down.</p><p>First, we refactored our setText action creator to call it updateText. This is because we want to use the setText action creator for our thunk, but we still need an action that can tell our reducer to update the text value in our store.</p><p>We also added an invalid flag to our state, along with an action creator for setting the flag, and the associated reducer function.</p><p>Lastly, we added our setText thunk. The actual functionality looks almost identical to what it looked like in the App component. Notice how there are multiple places where additional actions are dispatched. That allows us to update individual pieces of our state as the asynchronous operations complete, as well as wait for certain asynchronous operations to complete before updating other values in the state.</p><p>Now we can update our StartContainer component to use the new setText action creator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef24407b1fe8dcbef8df3c578f71e707/href">https://medium.com/media/ef24407b1fe8dcbef8df3c578f71e707/href</a></iframe><p>Our PlayContainer component can also be updated, since it can now get everything it needs from the Redux store, rather than relying on the App component to manage global state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29cb0f2ebf6071d160e129998c4a9cd7/href">https://medium.com/media/29cb0f2ebf6071d160e129998c4a9cd7/href</a></iframe><p>And lastly, our App component can forget about managing any state whatsoever.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3527a715fe26ee8923afb9c44183d2d/href">https://medium.com/media/b3527a715fe26ee8923afb9c44183d2d/href</a></iframe><p>Once you’ve made all these changes, you may notice that the “Start Over” button no longer works. This has to do with the fact that our StartContainer component is now triggering a redirect to the /play route if text is set in state. We’ll need to update the “Start Over” button to clear the text value, which will then trigger the navigation to the /start route (and stay there until text is set again).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/909d0c59a1ba4df39d4fd311a2bba74c/href">https://medium.com/media/909d0c59a1ba4df39d4fd311a2bba74c/href</a></iframe><p>And just like that, we’ve rewritten our entire application to make it look and function exactly the same! But seriously, we’ve made some real improvements by structuring our application to have a much clearer separation of concerns, and isolating our business logic so it can be more easily shared and tested.</p><h3>Turning it up to eleven</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*m_2HCQkVZMNa9wM_dHZSMQ.gif" /></figure><p>At this point we have the foundation for a scalable, enterprise React application. So we’re done, right? Well, not quite. Let’s take it to the next level and get <a href="https://en.wikipedia.org/wiki/Reactive_programming">reactive</a>!</p><p><a href="https://rxjs.dev/guide/overview">RxJS</a> is a library for composing asynchronous and event-based programs by using observable sequences. It provides types (Observable, Observer, Schedulers, Subjects) and operators (map, filter, reduce, every, etc.) to allow handling asynchronous events as collections. As the RxJS team puts it:</p><blockquote>Think of RxJS as Lodash for events.</blockquote><p>The power of RxJS comes from its ability to compose streams of data or events and transform them using pure functions to produce values that react to — or update based on — new data or events being pushed down from the streams.</p><p>If you’re not familiar with RxJS at all, it can be a little daunting at first. But don’t let that discourage you. Hopefully you can get at least the general idea from the sample code. You can also checkout <a href="https://www.learnrxjs.io/">learnrxjs.io</a>, which is a pretty great resource for getting started with RxJS.</p><p>To incorporate RxJS into our application, we’re going to use the <a href="https://redux-observable.js.org/">Redux Observable</a> middleware. Redux Observable allows us to treat dispatched actions and current state as streams, which are handled through <a href="https://redux-observable.js.org/docs/basics/Epics.html">epics</a>. Epics are just functions that take two Observables as parameters: one representing a stream of actions and the other representing a stream of the current state from the Redux store (they can also take a third argument, which is an object of injected dependencies, but we won’t get into that here). Within an epic you use RxJS operators to perform side-effects, transform data, and ultimately return a stream (Observable) that pushes new actions.</p><p>But enough talk, let’s get to it! Start by installing the Redux Observable library, along with RxJS:</p><pre>yarn add redux-observable rxjs</pre><p>Now we’re going to create an epic in our src/redux/modules/play.ts module. Remember, an epic is a function that takes an Observable of actions and optional Observable of state as parameters, and returns an Observable of actions — actions in, actions out.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecea24f1fa77708561f12189ef0800ff/href">https://medium.com/media/ecea24f1fa77708561f12189ef0800ff/href</a></iframe><p>Isn’t that so much better?!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3ohs7KViF6rA4aan5u%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3ohs7KViF6rA4aan5u%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3ohs7KViF6rA4aan5u%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="320" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f96104a16b25ebc548528d5b10d5c0a/href">https://medium.com/media/2f96104a16b25ebc548528d5b10d5c0a/href</a></iframe><p>OK, OK. I’ll admit this probably just looks like a more complicated way to do exactly what we were doing before. It’s hard to demonstrate the real power of RxJS in such a trivial example. But let’s at least go through it, then explore some ways that we can start to see the benefits of RxJS.</p><p>So the first thing we did was get rid of our setText thunk, and re-renamed our updateText action creator back to setText. Then we created a setTextEpic function. For this example we don’t need to access the current state, so we only included the first parameter, the Observable of actions. Our epic needs to return an Observable of actions, so we’re just going to return the current action$ Observable, using the pipe function to chain <a href="https://rxjs-dev.firebaseapp.com/guide/operators">operators</a> for transforming the data and performing side-effects.</p><p>Let’s step through our operators and see what they’re doing. First we use the <a href="https://redux-observable.js.org/docs/basics/Epics.html#a-basic-example">ofType</a> operator. This is a simple filter that will only emit actions down the chain that match the specified type. Typically an epic should be focused on handling a single action, and you write lots of epics to handle your various actions.</p><p>Next, we’re using the <a href="https://rxjs-dev.firebaseapp.com/api/operators/filter">filter</a> operator to ensure that we have a new value for the text before we continue down the chain. Filter will only emit actions that match the specified criteria. In our case, it will prevent us from performing all the validation logic when we’re clearing our text. It’s worth mentioning we could have combined ofType and filter into a single filter, but I wanted to demonstrate the ofType operator. Also be aware that actions don’t arrive to your epics until <em>after</em> they’ve gone through your reducers. According to the <a href="https://redux-observable.js.org/docs/basics/Epics.html">Redux Observable documentation</a>:</p><blockquote><em>Epics run alongside the normal Redux dispatch channel, </em><strong><em>after</em></strong><em> the reducers have already received them — so you cannot “swallow” an incoming action. Actions always run through your reducers </em>before<em> your Epics even receive them.</em></blockquote><p>So even though we aren’t processing any empty values in our epic, the text value in our store will still get updated when we clear it. Note that we also updated our reducer to convert our text to uppercase (rather than in our action), since it will reach the reducer before the epic.</p><p>After that, we use the <a href="https://rxjs-dev.firebaseapp.com/api/operators/filter">switchMap</a> operator which allows us to return an Observable (or Promise), which we’ll need to call our asynchronous lookupWord function. Inside the switchMap operator, things probably look very similar to our Promise-based solution. There are a couple of key differences: 1) We wrap our lookupWord calls with the <a href="https://rxjs-dev.firebaseapp.com/api/index/function/from">from</a> function, which creates an Observable from a Promise. And 2) we use the <a href="https://rxjs-dev.firebaseapp.com/api/index/function/forkJoin">forkJoin</a> function rather than Promise.all, which in a similar fashion takes an array of Observables and will give us a single Observable that emits an array of results when all of the Observables that were passed in emit a value.</p><p>At the end of it all, we emit a new action by returning the setInvalid action. It’s imperative that your Observable emits a new, and <em>different</em>, action. Otherwise you’ll create an infinite loop within your epic, which is generally considered to be a bad thing.</p><p>Now that we have an epic, we need to configure the Redux Observable middleware (at least, if we want it to work). First, we need to create a root epic. Similar to how Redux only allows a single root reducer, Redux Observable requires a single root epic. For convenience, they provide a combineEpics function which, similar to Redux’s combineReducers function, wraps any number of epics in a single root epic.</p><p>Let’s export our root epic from the same module as our root reducer, src/redux/root.ts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f94114b3fecf509b63603c2dfa81ba68/href">https://medium.com/media/f94114b3fecf509b63603c2dfa81ba68/href</a></iframe><p>And then we’ll configure the middleware in src/redux/configureStore.ts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ddd4bd37ec53790a4033c1ec7179e33/href">https://medium.com/media/4ddd4bd37ec53790a4033c1ec7179e33/href</a></iframe><p>It’s worth pointing out here the call to getDefaultMiddleware. This allows us to get the middleware already configured by Redux Toolkit, and add the epic middleware to it. Otherwise, we’d lose the middleware provided by Redux Toolkit.</p><p>You’ll also notice that after we configure our store, we make this call:</p><pre>epicMiddleware.run(rootEpic);</pre><p>That’s what starts up the actual processing of your epics alongside the normal Redux dispatch channel. And with that in place, we now have a fully functioning epic in our application!</p><h3>So why RxJS?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FuN5iwZB2v2dH2%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FuN5iwZB2v2dH2%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FuN5iwZB2v2dH2%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="245" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f1593936788e28642f7f1c7a3f235b6/href">https://medium.com/media/3f1593936788e28642f7f1c7a3f235b6/href</a></iframe><p>As I mentioned earlier, RxJS can be overwhelming at first, and it’s hard to see its real value in such a trivial example. So let’s try adding some functionality that has real value and hopefully shows some of the advantages of RxJS.</p><p>Suppose, for the sake of this example, our requests to the dictionary API take a very long time … perhaps there’s some issue with the API or our user has a very slow internet connection. Then also suppose that a user enters in a sentence which ships off a bunch of HTTP requests, then decides to change their sentence. When they click “Start Over” and enter in a new sentence, it will ship off another batch of HTTP requests. But if the first batch of requests haven’t completed yet, the new batch will just get queued up and wait for the others to complete first. Not to mention, when the first batch does complete the responses will run through our reducers even though we no longer care about those responses.</p><p>So what can we do about this? One of the big advantages of Observables over Promises is that Observables are cancellable. So in theory, we should be able to cancel our requests when the user navigates away from the /play route.</p><p>The first thing we’ll need to do is update our dictionaryApi service to use the RxJS <a href="https://rxjs-dev.firebaseapp.com/api/fetch/fromFetch">fromFetch</a> function, rather than the global fetch. The fromFetch function is a simple wrapper around the global fetch function that returns an Observable rather than a promise. Additionally, it automatically sets up an <a href="https://developer.mozilla.org/en-US/docs/Web/API/AbortController">AbortController</a>, which allows us to not only cancel the subscription on the Observable, but cancel the HTTP request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5874a4ad19a2d3c42c39c13a8d359a7/href">https://medium.com/media/c5874a4ad19a2d3c42c39c13a8d359a7/href</a></iframe><p>Next, we’ll need to update our setTextEpic so it knows when to cancel any pending requests. The Redux Observable documentation gives us a <a href="https://redux-observable.js.org/docs/recipes/Cancellation.html">recipe for cancellation</a> that uses the <a href="https://rxjs-dev.firebaseapp.com/api/operators/takeUntil">takeUntil</a> operator to trigger a cancellation when a cancellation action is dispatched.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5f87deaa34bacf566a9fdd558258485/href">https://medium.com/media/c5f87deaa34bacf566a9fdd558258485/href</a></iframe><p>As you can see, we’ve added a cancelSetText action creator, as well as adding the takeUntil operator to our forkJoin. The takeUntil operator takes a notifier Observable as its only parameter. It emits the values from the source Observable until a value is emitted from the notifier Observable, at which point it completes, effectively cancelling our upstream Observables including any pending HTTP requests. For our notifier Observable, we’re simply going to use our action$ stream and filter for our cancelSetText action. So now if we dispatch the cancelSetText action, it will cancel any pending requests. Pretty slick!</p><p>The last thing we need to do is update our PlayContainer component to dispatch the cancelSetText action when a user navigates away. We can do this by tapping into our existing useEffect hook. The useEffect hook already has a <a href="https://reactjs.org/docs/hooks-effect.html#effects-with-cleanup">built-in clean-up mechanism</a>. By returning a function from our useEffect hook, React will automatically run that function any time the component unmounts (such as when navigating away). So we just need to return a function that dispatches our cancelSetText action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e2520aaa4bdf0cf91203b91196f9047/href">https://medium.com/media/5e2520aaa4bdf0cf91203b91196f9047/href</a></iframe><p>Although still a somewhat trivial example, I hope you’re starting to see the advantages we gain through RxJS.</p><p><em>If you’re feeling ambitious, as an additional exercise try adding retry logic with an exponential backoff to your API requests using RxJS. (Hint: check out the </em><a href="https://rxjs-dev.firebaseapp.com/api/operators/retryWhen">retryWhen</a><em> operator.)</em></p><h3>We did it!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*-H1gBpnPlIc5pt5VBavj-A.jpeg" /></figure><p>Wow, what a ride! We’ve covered making asynchronous calls to fetch data; using Redux to manage global application state; using memoized selectors to efficiently compute derived state; using Redux Thunk for dispatching simple actions with side-effects; and took things to the next level for more complex state management with RxJS and Redux Observable.</p><p>At this point, we’ve covered most of our business logic and data layers of our application diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*nZ8AU5DluLwmLQdtZesOIw.png" /></figure><p><em>For those looking for an additional challenge, take your new found knowledge of Redux middleware and try persisting your gameplay state in local storage with </em><a href="https://github.com/rt2zz/redux-persist"><em>Redux Persist</em></a><em>.</em></p><p>I hope these tutorials have helped you learn some useful patterns and practices to help you build scalable, enterprise-ready React applications in the real world. Now go and build something awesome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76b407607df8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/building-a-react-application-part-ii-76b407607df8">Building a React Application: Part II</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[End to End testing with React and Cypress]]></title>
            <link>https://medium.com/imaginelearning/end-to-end-testing-with-react-and-cypress-30ab8f105432?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/30ab8f105432</guid>
            <dc:creator><![CDATA[Emily Williams]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 19:31:21 GMT</pubDate>
            <atom:updated>2020-07-14T21:30:05.712Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UBB4OojxnQFvQ59lq8mp9A.png" /></figure><p>The purpose of this article is going to be from an absolute beginner’s perspective on how to set up Cypress and do End to End testing on a simple react application. Before we begin here is a link to Cypress documentation for added clarity <br> <a href="https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell">https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell</a></p><p><strong>Now let’s get started.</strong></p><p>First, we need to install Yarn on your machine.</p><p>For Windows <a href="https://classic.yarnpkg.com/en/docs/install#windows-stabler">https://classic.yarnpkg.com/en/docs/install#windows-stable</a></p><p>For Mac <a href="https://classic.yarnpkg.com/en/docs/install#mac-stable">https://classic.yarnpkg.com/en/docs/install#mac-stable</a></p><p>Create a folder on your computer for your project to be<br> Open your terminal and cd into the newly created folder.</p><pre>## clone this repo to a local directory</pre><pre><a href="https://github.com/emilystaheli/CypressVisionconference">https://github.com/emilystaheli/CypressVisionconference</a></pre><pre>git clone https://github.com/&lt;yourUsername&gt;/CypressVisionconference.git</pre><pre>## cd into the cloned repo</pre><pre>cd CypressVisionconference/</pre><pre>## install the node_modules</pre><pre>yarn install</pre><pre>## start the local webserver</pre><pre>yarn start<br> navigate to <a href="http://localhost:8888/#/">http://localhost:8888/#/</a> to test that it’s working</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*q4aqoYZ5HXmnqc08zHsDpg.png" /></figure><p><strong>Install Cypress</strong></p><p>Once you have the above project up and running, it’s time to get started installing Cypress.</p><p>Navigate to your project directory. Run the following command.</p><pre>yarn add cypress --dev</pre><p>This install may take a few minutes as it will install the Javascript package and the Cypress binary needed to execute tests.</p><p>If you get an error saying Cypress failed to start, this could be caused by a missing library or dependency.</p><p>Run</p><pre>Npx cypress install --force</pre><p>Now lets open Cypress by running the following command</p><pre>yarn run cypress open</pre><p>When this command runs, it will open the Cypress test runner. Since this is the first time we are running it, it will generate the folder structure and some sample tests. Once the UI opens, feel free to spend some time familiarizing yourself with the test runner.</p><p>Now let’s look at the file structure that was generated. There will be a cypress folder that gets initialized inside the root directory of your application. Inside that folder, four more will also have been created.</p><pre>- cypress</pre><pre>|- fixtures</pre><pre>|- integration</pre><pre>|- plugins</pre><pre>|- support</pre><p><strong>Fixtures</strong></p><p>The fixtures folder is where you can store static data used throughout your tests. This can include test data or mock responses.</p><p><strong>Integration</strong></p><p>This folder is where all of your tests will live. The sample tests that you experimented with earlier will all have been generated here.</p><p><strong>Plugins</strong></p><p>Cypress has a node process that can be used to extend some of its functionality. This includes configuring file pre-processors or loading configurations.</p><p><strong>Support</strong></p><p>Out of the box, Cypress provides the support/index.js file that will be run before every spec file. It can be used for several things such as a global beforeEach hook, overrides, and setting up custom commands.</p><p><strong>Now that Cypress is running let’s write some End to End tests.</strong></p><p>We are going to be doing several tests with Cypress using todoMVC. The application will give you a good variety of writing tests in Cypress.</p><p>First, navigate to cypress/integration In the integration folder create a new spec file called input-form.spec.js</p><p>Let’s start by testing the input form</p><p>At the top of the input-form.spec.jsadd</p><pre>/// &lt;reference types=&quot;cypress&quot; /&gt;</pre><p>By adding this line in your tests makes it possible for IntelliSense to work with Cypress</p><p>All Cypress tests will need to be inside a describe and an it block; a describe block describes what your test is doing, and an it block says what you are testing.</p><p><strong>Loads the site</strong><br> So add a describe block and start the first test with an it. Before we test any behavior, we need to visit the page first. To do this we use the command cy.visit(“)</p><pre>describe(&#39;Input form&#39;, () =&gt; {<br>  it(&#39;opens the site&#39;, () =&gt; {<br>     cy.visit(&#39;localhost:8888&#39;); //this is the server that was started earlier<br>   })<br>})</pre><p>Before we continue, let’s make sure that we can reach our application. <br> Startup cypress with</p><pre>yarn run cypress open</pre><p>When Cypress opens choose input-form.spec.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Fo0lIXmbyF0E1Dsj54qytQ.png" /></figure><p>Now let’s verify that it loads the page. Click on input-form.spec.js when Cypress runs. We will see the description from the describe block and the individual test description.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*S8kQunZCl-gN3w-sMB37Aw.png" /></figure><p>Now that we verified that the site is working let’s write some more tests</p><p><strong>Test user input</strong></p><p>First, let us test that the input is working and that we will accept input from the user. We will need to select the input form and type what we want to put in the todo. One difference that Cypress has with selenium is that it doesn’t use the ‘by’ selectors that selenium uses. Instead, We will be using cy.get(‘’) to select the element. Cypress makes it easy to find out what selector you need. Run Cypress and use the cypress selector tool and hover over the elements that you want to select then click on the Copy icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*WiX87T6pZJfUgL1bB_9gIA.png" /></figure><p>The selector that Cypress selected is .new-todo, so let’s put that with the cy.get(). If you want to place text in an input field, you will need to use cy.type() command.</p><p>After the text is entered into the input-form, we want to check that the text is correct. We will do this by adding .should at the end of the .type method and chain them together.</p><pre>it(&#39;check input text&#39;, () =&gt; {</pre><pre>cy.get(&#39;.newtodo&#39;).type(&#39;Vision Conference&#39;).should(&#39;have.value&#39;, &#39;Vision Conference&#39;);</pre><pre>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*ylgBvZe5gdY6hWHv1_aLRg.png" /></figure><p><strong>Check that task is entered and saved.</strong></p><p>After the text is entered into the input-form, we still have to click the enter button to add the item; this is done by adding {enter} in the cy.type. In the todos, let’s check to see if the todo is added correctly. Select the todo item.</p><pre>it(&#39;check input text&#39;, () =&gt; {<br>  cy.get(&#39;.new-todo&#39;).clear()<br>  cy.get(&#39;.new-todo&#39;).type(&#39;Vision Conference{enter}&#39;)<br>  cy.get(&#39;.todo-list li&#39;).should(&#39;have.text&#39;, &#39;Vision Conference&#39;);<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*b0t9cOKF4G-3mAEMDeWKjg.png" /></figure><p>Let’s go ahead and add a few more items in the todos and check that we can enter multiple items. create three variables at the top of your file before the describe block</p><pre>var TODO_ITEM_ONE = &#39;Virtual Adventure&#39;;<br>var TODO_ITEM_TWO = &#39;Booster Bingo&#39;;<br>var TODO_ITEM_THREE = &#39;Lip Sync Contest&#39;;</pre><p>Now create a new it block creating three new todos.</p><pre>it(&#39;should add multiple todos&#39;, ()=&gt;{<br>  cy.get(&#39;.new-todo&#39;).type(TODO_ITEM_ONE+&#39;{enter}&#39;)<br>  cy.get(&#39;.new-todo&#39;).type(TODO_ITEM_TWO+&#39;{enter}&#39;)<br>  cy.get(&#39;.new-todo&#39;).type(TODO_ITEM_THREE+&#39;{enter}&#39;)<br>})</pre><p>Now let’s test that we have all the items. To check items in a list, we will use the .eq() .ea(0) would be the first item in the list eq(1) will be the second and so forth.</p><pre>it(&#39;should have append new items to the bottom of the list&#39;, () =&gt; {<br>  cy.get(&#39;.todo-list li&#39;).eq(0).find(&#39;label&#39;).should(&#39;contain&#39;,    &#39;Vision Conference&#39;)<br>  cy.get(&#39;.todo-list li&#39;).eq(1).find(&#39;label&#39;).should(&#39;contain&#39;,  TODO_ITEM_ONE)<br>  cy.get(&#39;.todo-list li&#39;).eq(2).find(&#39;label&#39;).should(&#39;contain&#39;, TODO_ITEM_TWO)<br>  cy.get(&#39;.todo-list li&#39;).eq(3).find(&#39;label&#39;).should(&#39;contain&#39;, TODO_ITEM_THREE)<br>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*gt4NlDmkXIHpEyF19hjgig.png" /></figure><p><strong>Edit a task</strong></p><p>Let’s go ahead and test that we can edit a task. For this test, we will use the eq() method to find the item and <a href="https://docs.cypress.io/api/commands/dblclick.html#Syntax">cy.dblclick()</a> to click inside the item. Let’s go ahead and edit Virtual Adventure and change it to Learn Cypress.</p><pre>it(&#39;should allow me to edit an item&#39;, () =&gt; {<br>  cy.get(&#39;.todo-list li&#39;).eq(1).find(&#39;label&#39;).dblclick()<br>  // clear out the inputs current value<br>  // and type a new value<br>  cy.get(&#39;.todo-list li&#39;).eq(1).find(&#39;.edit&#39;).clear().type(&#39;Learn    Cypress&#39;).type(&#39;{enter}&#39;)</pre><pre>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_0cjv5VNrl-oUkIHAU9WCQ.png" /></figure><p><strong>Debug Tests in Cypress</strong> <br> Now let’s take a look at what Cypress does when there is a problem with our code. First, we will use the <a href="https://docs.cypress.io/guides/core-concepts/test-runner.html#Command-Log">Cypress Command Log</a>, and then we’ll use the developer tools within our cypress test runner. Let’s go ahead and check that the footer is available when adding a todo Open cypress and run the file.</p><pre>it(&#39;Checks footer is available after adding item&#39;, () =&gt;{<br>cy.get(&#39;.footer&#39;).should(&#39;be.visible&#39;);<br>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*hy3rnJvBNHcgARY0l4Fe8g.png" /></figure><p>The nice thing about Cypress is that you can go back and see what happened before and after the test failed. You can click on any test and see what happened. In this test case, it looks like the .footer is not visible.</p><p>Let’s go ahead and fix the problem.</p><pre>it(&#39;check todo item&#39;, () =&gt; {<br>  cy.get(&#39;.new-todo&#39;).clear()<br>  cy.get(&#39;.new-todo&#39;).type(&#39;Vision Conference{enter}&#39;)<br>  cy.get(&#39;.todo-list li&#39;).should(&#39;have.text&#39;, &#39;Vision Conference&#39;);<br>});</pre><pre>it(&#39;Checks footer is available after adding item&#39;, () =&gt;{<br>  cy.get(&#39;.footer&#39;).should(&#39;be.visible&#39;); //checks for footer after     item is entered<br>})</pre><p>Now that we learned how to debug, it’s time for you to experiment on writing tests. Below is a list of tests that you can try on your own be sure to use cypress documentation <a href="https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell">https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell</a> if you need help along the way.</p><h3>Additional tests to write</h3><p><strong>Check that there are No items entered.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wCbSaQzP51psotF6YzYhZA.png" /></figure><p><strong>When an item is entered, the text input field should clear.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dSZd6CmNwn882c_ZQfJQlw.png" /></figure><p><strong>When all items are completed, Check the All tab says 0 items left.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vbBlFTSUlgVaEN3SxkeyBw.png" /></figure><p><strong>When all items are completed, Check the Active tab should not have any items.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKXVDmGdVuje3O-m2jccLA.png" /></figure><p><strong>When all items are completed, Check, the Completed tab should have all the items listed.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2HmLSgwr2ivrU3OjkLvEA.png" /></figure><p><strong>Check that when you select an item, the item is crossed out (</strong><a href="https://docs.cypress.io/guides/references/assertions.html#Chai-jQuery"><strong>have.class </strong></a><strong>could be helpful)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LhlzZ1qGULIGIvS6GH6d9w.png" /></figure><p><strong>When Clear completed is entered, it clears the completed tasks.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GKmRXvm-6ZBOm9J5HrG_6g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4PiMTXWLlItewgTPLxGT1A.png" /></figure><p><strong>The delete icon should remove the selected task.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bL7LOtPAgt-St5jYJM0Jvg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zWGeUoymMDWOz7bwNLbazA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30ab8f105432" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/end-to-end-testing-with-react-and-cypress-30ab8f105432">End to End testing with React and Cypress</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Year as a Software Engineer]]></title>
            <link>https://medium.com/imaginelearning/my-first-year-as-a-software-engineer-be3cac2d47eb?source=rss----600b25e4e7c2---4</link>
            <guid isPermaLink="false">https://medium.com/p/be3cac2d47eb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Enoch Robinson]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 19:23:17 GMT</pubDate>
            <atom:updated>2020-08-03T03:33:19.707Z</atom:updated>
            <content:encoded><![CDATA[<h3>10 things every new engineer should know</h3><p>I still remember my first year as an engineer. I’ll never forget the sense of pride when I first solved the impossible. It was also a year full of lessons learned. The first (and last) time I wiped out a critical table or realizing the waste of time coding because you didn’t ask to fully understand a story. I’ve made plenty of mistakes. Here are 10 things I learned that first year.</p><p><strong>1. Plan your code</strong></p><p>I cannot stress enough how important it is to have a semblance of a plan before you write your first line of code. I’ve noticed a correlation in which engineers who plan their code, will write less and cleaner code. It’s not uncommon you’ll jump in and start writing code. Especially the first year. Start by breaking down the story into logical chunks. Flow chart it if it helps. You can then pseudo code it to outline your structure of logic. Some engineers write a bunch of comments first, then write in the code. Figure out your planning style to help you break down your work.</p><p><strong>2. Don’t Assume Your Solution</strong></p><p>In school, I was given the following puzzle:</p><p>“Write a snippet of code that will always produce an even random number between 0 &amp; 50”</p><p>At first glance, this puzzle seems to make people think they need division to solve it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*gTTSgY1ljkrXTVeIY6FS9g.png" /><figcaption>My first attempt to solve the puzzle.</figcaption></figure><p>After a few seconds of thinking it through, you’ll realize a check is needed to ensure a return of an even number. Using the Modulus Operator, we can verify the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*05GRBHXufRq00V9O43Z3zw.png" /><figcaption>Dealing with odd numbers.</figcaption></figure><p>While the above works, following the division path led to an inefficiency. You may already see another solution, without any checks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*teKZxrmiu9AOBLj8kaj54w.png" /><figcaption>A much more efficient solution.</figcaption></figure><p>In my first year, I would hear a problem and immediately start solving it in my head. I would plan out my code using that first solution. I learned to take my time, think it through, and ask questions. Your code may work, but make sure it accounts for most/all scenarios and its efficiently written.</p><p><strong>3. Asking Questions</strong></p><p>Being a new engineer, I had all sorts of questions. I’m not afraid to ask questions, but I quickly learned that I was bothering senior members when they too had work to complete.</p><p>When you are new, your peers are more lenient about how often you can interrupt and ask questions. Take advantage of this during your first two weeks on the job. Ask to your hearts content, being mindful of the time you are taking away from others. After a few weeks, ask during noted down times. For example, just before meetings start and right after they end, you’ll find a few minutes to sneak in a question. If you hear a senior or lead engineer offer their time, use it.</p><p>As you gain experience, you won’t have less questions, but you’ll learn where to find the answers. Start with the official documentation (ie Javadocs, .NET documentation) to learn the original intent of the technology stacks and frameworks. Google, StackOverflow, and Reddit Programming are good options as well. For me, it lead to a different problem: not asking enough questions.</p><p>I started spending too much time researching. After a certain point, researching won’t help you. You’ll need figure out that cut off point, but generally it will be a couple of hours at least. I found most of my answers (during my first year), on average, within three hours. If I didn’t have an answer, I’d take a break, then try for another hour. If still no answer, then I’d ask. By this point, I thoroughly researched my topic and my questions were better defined. My peers appreciated this and were more willing to answer my questions when they saw me raise my hand. Over time, my research times dropped as my knowledge increased.</p><p><strong>4. Code Bloat</strong></p><p>In my first year, I rarely wrote perfect code on my first attempt. Typically, after planning, I would write a section of code, then realize I needed to make some adjustments. This would repeat a few times before I completed the section. Next, I would branch out to other sections, building off what I originally created. After a few iterations, my code looked different than originally intended. But code compiled without errors and I could turned it in.</p><p>My code was not clean. Over time, my code would slow down productivity. It made debugging harder and adding new code like navigating a land mine. Here are some guidelines to help you be aware of what to avoid:</p><p>· Redundant variables</p><p>· Unused logic in code</p><p>· Irrelevant logic in code</p><p>· Inefficient logic</p><p>· An object that knows to much (AKA God Object)</p><p>· Code is hard to read</p><p>If you see any of these, or you aren’t sure if the code is bloated, always ask a Senior or Lead Engineer on your team for direction. Over time, code grows and eventually you have unnecessarily long, slow or wasteful logic. It is almost impossible for a new engineer to discern the impact of refactoring. Review this JavaScript sample of code I found online:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*aBTdh5jddXZMXTrwRa2FpA.png" /><figcaption>Bloated JavaScript Code</figcaption></figure><p>Here it is simplified:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6BZA7yZhAxH_bt8fTvusw.png" /><figcaption>Simplified JavaScript Code</figcaption></figure><p>Not only is the simplified version shorter, but it’s easier to read. Try to write clean code. Your best indicator of clean code is you won’t get questions on what your code does. There are good resources out there on how to write clean code, read or watch them.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7EmboKQH8lM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7EmboKQH8lM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7EmboKQH8lM%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e944856974efd49b22206a88166e108e/href">https://medium.com/media/e944856974efd49b22206a88166e108e/href</a></iframe><p><strong>5. Magic Numbers</strong></p><p>I often encountered a loop that needed a specific number of iterations before it exited. Knowing that number, I added the value directly in the code. No variable, no comment, just a number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*s9YRQk5ddiQDdx3BRFh4Kg.png" /><figcaption>Why seven?</figcaption></figure><p>Quick, easy and done. The next engineer will understand that this will loop seven times, but they will not know why its looping seven times. If months or years pass before another review, it may need to be run several times to understand why it loops seven times. Or you’ll need to ask the original coder, why seven? Coding shouldn’t be a philosophizing endeavor. At the very least, you comment the code why the magic number is used. When possible, avoid them.</p><p><strong>6. Shotgun Surgery</strong></p><p>If you ever hear another engineer during a planning session mention that the same logic will be needed in multiple places, immediately identify why. If you discover the need to use the same code in multiple places, do not cut and paste the code, talk to your team.</p><p>It seems much quicker to copy code in multiple places versus thinking through and properly abstracting your code. However, you’ll spend far more time tracking all your copied code to make a change, rather than updating one place.</p><p>On a side note, some people struggle growing their careers by spending too much time maintaining various aspects of lower tier work. This keeps them from developing the necessary skills to get promoted. And it doesn’t help that your peers will struggle trying to fix your code and may provide negative reviews.</p><p><strong>7. Hard Coding</strong></p><p>In my first coding job, I was tasked to create a web interface for an old flat file database. They didn’t need an elaborate solution, something quick they could use for those rare cases that came up for review.</p><p>The file wasn’t large, loading it into memory was reasonable. I worked with our network guys to ensure the file was hosted in a shared directory with the required permissions. Then, coded the path directly into my logic.</p><p>Hard coding prevents us from obtaining data from an external source. As you may have already surmised, the path was changed and my code broke. Thankfully, I gracefully handled the error with “Network guys moved the file so don’t blame me” and it was easy to track the new path.</p><p>While easy to fix, it took longer than necessary. I had to recompile my code and run it through our deployment process. Had I placed it in the web config file, a quick update would have solved my problem much faster. This issue is exasperated with large code bases that take a long time to compile. If external data is required, work with your senior or lead engineer to learn where you can keep it to avoid a full recompile. This problem is made worse during a critical hot fix that impacts customer ability to use the product.</p><p><strong>8. Speed vs Quality</strong></p><p>Is it better to create code quickly or create quality code? Most engineer will answer quality code is best. Yet, when faced directly with this challenge, we tend to pick speed. Business always want to go fast. New engineers have the added pressure of watching their peers complete their work faster than they can. Who gets the good work? The fast ones! Or so it seems.</p><p>As a new engineer, writing code quickly is what led to most of the lessons I learned. If you write quality code, you will naturally be fast. Completing your task quickly won’t matter if code reviews or QA is often returning your work. Focus on quality, always. As Robert Martin says, “You’ll only go fast if you go well.”</p><p><strong>9. Excessive Abstraction</strong></p><p>After a few months on my first coding job, I often needed to make database call to obtain the same information. At this point, I had several internal web pages all dealing with Employee data. Since I was given each page to work on individually, I never thought to abstract my database calls into its own class that could be shared across the pages.</p><p>Once it hit me, I quickly made a new class and moved all my database calls into it. As I was moving my database calls, I noticed something. I always had to connect to the same database, always pulled three pieces of data, and always had to close the connection. I abstracted these pieces into their own methods.</p><p>I further realized; my queries could be programmatically built. I abstracted my query string builder so I could build any query by only sending the fields and tables to a method that would generate the query. I further abstracted my table selector string so I could send a name or number to add to my query string builder to get the table or tables I needed.</p><p>When I was done, it was a mess. It was difficult to debug whenever a query was malformed, and worse, performance optimization was nearly impossible since it only built to use one type of join. Sure, I could have handled that, but it wasn’t worth it. Opening and closing my database connections was all the abstraction I needed. It helped simplify maintaining my connection strings. By keeping everything else where I used it, I could easily optimize the query for its specific purpose.</p><p>There are all sorts of opinions on how much is too much or too little abstraction. With experience, you’ll learn to balance your abstractions. Work with your leads or senior engineers, they have the experience and will guide you properly. I thankfully do not have this sample of code to share.</p><p><strong>10. Performance Costs</strong></p><p>Learn the costs of whatever pattern, structure, or database calls you use. While memory is cheap now, time isn’t. Poor performing code can lead to longer load, processing and/or debugging times. Generally, this isn’t an issue until you work with large datasets or code bases.</p><p>Most engineers code with a small or limited data sets on hand. While the logic may be sound, performance may not. Keep in mind to test your code with larger datasets for performance. Queries are notoriously inefficient when not properly optimized. Performance, like QA, starts with the engineer.</p><p><strong>Conclusion</strong></p><p>Hopefully you found this helpful, especially if you’re new to engineering. Keep trying, don’t be afraid to fail and you’ll make it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be3cac2d47eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/imaginelearning/my-first-year-as-a-software-engineer-be3cac2d47eb">My First Year as a Software Engineer</a> was originally published in <a href="https://medium.com/imaginelearning">Imagine Learning Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>