<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>software engineering on Daniel Adams Tech</title>
    <link>https://blog.danieladamstech.com/tags/software-engineering/</link>
    <description>Recent content in software engineering on Daniel Adams Tech</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 30 Oct 2023 21:00:00 -0400</lastBuildDate>
    <atom:link href="https://blog.danieladamstech.com/tags/software-engineering/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Measuring Entrypoint Layer Latency in NewRelic</title>
      <link>https://blog.danieladamstech.com/2023/measuring-entrypoint-layer-latency-in-newrelic/</link>
      <pubDate>Mon, 30 Oct 2023 21:00:00 -0400</pubDate>
      <guid>https://blog.danieladamstech.com/2023/measuring-entrypoint-layer-latency-in-newrelic/</guid>
      <description>In a microservices environment where services align to team boundaries, many times it will be necessary to call a service owned by another team. My team is responsible for the customer-facing external API layer for B2B transactions. We maintain multiple versions of MISMO APIs and handle security, logging, monitoring, and mapping the customer request to a standardized data format for our internal APIs. The APIs we are fronting do a lot of work.</description>
      <content:encoded><![CDATA[<p>In a microservices environment where services align to team boundaries, many times it will be necessary to call a service owned by another team. My team is responsible for the customer-facing external API layer for B2B transactions. We maintain multiple versions of 
<a href="https://www.mismo.org/" target="_blank" rel="noopener">MISMO</a>
 APIs and handle security, logging, monitoring, and mapping the customer request to a standardized data format for our internal APIs. The APIs we are fronting do a lot of work. They run large rule sets and bookkeeping for mortgage insurance rate quotes or orders. Some are even dependent on external APIs like a credit pull. This leads to variance in response time.</p>
<p>As the customer-facing team, we want to ensure all our customers have a good experience. This leads us to track the overall system response time. However, it is hard to track the performance of our own code via that metric as our code accounts for less than 5% of the total transaction time. How then can we set up meaningful alerts for our team&rsquo;s performance? We need to track timing at the team microservice boundary. This is simple when you&rsquo;re the &ldquo;leaf node&rdquo; on the downstream side. However, the entrypoint layer takes time on the front end and back end of the transaction. We need to identify a span in the distributed trace that represents the &ldquo;noise&rdquo; in measurement that we want to remove and then subtract that duration from the outer span. This requires a bit of playing around with platform-specific query capabilities. In batch SQL, options are not very constrained, but sometimes approach needs to be adapted a bit to fit a streaming data analysis pipeline like the one that drives monitoring alerts.</p>
<p>The query below attempts to execute this strategy. The where clause pulls in both the outer and inner transactions into the intermediate result set. Then the <code>filter()</code> portion calculates two metrics from the bisection of that result set by microservice and figures the difference.</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="k">FROM</span><span class="w"> </span><span class="n">Span</span><span class="w"> </span><span class="k">SELECT</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="n">filter</span><span class="p">(</span><span class="n">percentile</span><span class="p">(</span><span class="n">duration</span><span class="p">,</span><span class="w"> </span><span class="mi">90</span><span class="p">),</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">appName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;Entrypoint Layer&#39;</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="n">filter</span><span class="p">(</span><span class="n">percentile</span><span class="p">(</span><span class="n">duration</span><span class="p">,</span><span class="w"> </span><span class="mi">90</span><span class="p">),</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">appName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;Last Hop to Include&#39;</span><span class="p">)</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">entrypointLayerDuration</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">WHERE</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="p">(</span><span class="n">appName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;Entrypoint Layer&#39;</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">TransactionCustomAttributeName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;CustomValue&#39;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="k">or</span><span class="w"> </span><span class="p">(</span><span class="n">appName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;Last Hop to Include&#39;</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;External/destination.corp.net/CommonsHttp/execute&#39;</span><span class="p">)</span><span class="w">
</span></span></span></code></pre></td></tr></table>
</div>
</div><p>This query works as long as the first and last hop queries can uniquely retrieve transactions under measurement. For example, if two different transactions in the last hop microservice made a call to the same uninstrumented DNS name, the second half of the query would pull in more traces and skew the timing. Another situation where this query would have a problem is when the entrypoint service errors and quickly returns. This could be due to invalid data format, bad auth, etc. That drives down the outer duration to nearly instantaneous while the inner duration only accounts for transactions that made it all the way to the last hop service and remains as usual. The metric could go negative in that case.</p>
<p>NewRelic 
<a href="https://newrelic.com/blog/how-to-relic/subquery-joins" target="_blank" rel="noopener">recently rolled out</a>
 
<a href="https://docs.newrelic.com/docs/query-your-data/nrql-new-relic-query-language/nrql-query-tutorials/subquery-joins/" target="_blank" rel="noopener">subquery joins.</a>
 which can help combat that issue. I tested this query with a mix of all-the-way-through and short-circuited transactions, and it does give accurate results. While the other query can cover a long timeseries, this one is relatively limited due to what I&rsquo;m assuming is the cardinality requirement of the join. It is not allowed for an alert query, even without <code>limit max.</code> The explicit <code>limit max</code> is required in the ad-hoc query to get the full result set or only about 10 rows will be returned. I&rsquo;ll continue to work with NewRelic to figure a workaround on how to get this working in alerts. I might end up falling back to creating another custom attribute on the entrypoint service that allows me to only select the desired traces for the <code>filter()</code> style query.</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="k">From</span><span class="w"> </span><span class="n">Span</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="k">JOIN</span><span class="w"> </span><span class="p">(</span><span class="k">FROM</span><span class="w"> </span><span class="n">Span</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="n">trace</span><span class="p">.</span><span class="n">id</span><span class="w"> </span><span class="p">,</span><span class="w"> </span><span class="n">duration</span><span class="w">  </span><span class="k">as</span><span class="w"> </span><span class="n">innerDuration</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">appName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;Last Hop to Include&#39;</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;External/destination.corp.net/CommonsHttp/execute&#39;</span><span class="w"> </span><span class="k">LIMIT</span><span class="w"> </span><span class="k">MAX</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="k">on</span><span class="w"> </span><span class="n">trace</span><span class="p">.</span><span class="n">id</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">SELECT</span><span class="w"> </span><span class="n">percentile</span><span class="p">(</span><span class="n">duration</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">innerDuration</span><span class="p">,</span><span class="w"> </span><span class="mi">90</span><span class="p">)</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">entrypointLayerDuration</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="k">WHERE</span><span class="w"> </span><span class="p">(</span><span class="n">appName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;Entrypoint Layer&#39;</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">TransactionCustomAttributeName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;CustomValue&#39;</span><span class="p">)</span><span class="w"> </span><span class="k">LIMIT</span><span class="w"> </span><span class="k">MAX</span><span class="w">
</span></span></span></code></pre></td></tr></table>
</div>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Framework-ish Dependencies</title>
      <link>https://blog.danieladamstech.com/2023/framework-ish-dependencies/</link>
      <pubDate>Sat, 14 Oct 2023 18:00:00 -0400</pubDate>
      <guid>https://blog.danieladamstech.com/2023/framework-ish-dependencies/</guid>
      <description>In software development, we generally must use dependencies to efficiently get more complex functionality we don&amp;rsquo;t want to write ourselves. However, there are some types of dependencies that prove to be more painful when maintaining software than others. Fewer dependencies leads to less upgrade work including less security vulnerability remediation work. Below I rank categories of dependencies with respect to the likelihood to have coupling issues during framework upgrades.
The Dependencies Good: broadly adopted, well-maintained dependencies that provide necessary functionality orthogonal to the framework (Spring Boot) AWS SDK , MapStruct , JAXB used in another project Not ideal, but necessary: coupled to the framework, but necessary functionality SpringFox for OpenAPI spec generation Probably not necessary: small uses of convenience functions or premature optimizations Pulling in the full Apache Commons Collections just for CollectionUtils.</description>
      <content:encoded><![CDATA[<p>In software development, we generally must use dependencies to efficiently get more complex functionality we don&rsquo;t want to write ourselves. However, there are some types of dependencies that prove to be more painful when maintaining software than others. Fewer dependencies leads to less upgrade work including less security vulnerability remediation work. Below I rank categories of dependencies with respect to the likelihood to have coupling issues during framework upgrades.</p>
<h2 id="the-dependencies">The Dependencies</h2>
<ol>
<li><strong>Good:</strong> broadly adopted, well-maintained dependencies that provide necessary functionality orthogonal to the framework (Spring Boot)
<ul>
<li>
<a href="https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html" target="_blank" rel="noopener">AWS SDK</a>
, 
<a href="https://mapstruct.org/" target="_blank" rel="noopener">MapStruct</a>
, 
<a href="https://javaee.github.io/jaxb-v2/" target="_blank" rel="noopener">JAXB</a>
 used in another project</li>
</ul>
</li>
<li><strong>Not ideal, but necessary:</strong> coupled to the framework, but necessary functionality
<ul>
<li>
<a href="https://springfox.github.io/springfox/" target="_blank" rel="noopener">SpringFox</a>
 for 
<a href="https://swagger.io/specification/" target="_blank" rel="noopener">OpenAPI spec</a>
 generation</li>
</ul>
</li>
<li><strong>Probably not necessary:</strong> small uses of convenience functions or premature optimizations
<ul>
<li>Pulling in the full 
<a href="https://commons.apache.org/proper/commons-collections/" target="_blank" rel="noopener">Apache Commons Collections</a>
 just for <code>CollectionUtils.isNotEmpty()</code>, explicitly overriding to use 
<a href="https://hc.apache.org/index.html" target="_blank" rel="noopener">Apache HTTP client</a>
 instead of the Spring Boot default for a low-traffic service</li>
</ul>
</li>
<li><strong>Bad:</strong> tightly coupled to the framework but not officially supported by the framework team
<ul>
<li>
<a href="https://github.com/derjust/spring-data-dynamodb" target="_blank" rel="noopener">Derjust Spring Data DynamoDB</a>
 stopped being maintained but required major code reorganization to remove.</li>
</ul>
</li>
</ol>
<h2 id="the-story">The Story</h2>
<p>I was upgrading a small service that persisted configuration data in DynamoDB and called a couple of upstream APIs. It was developed and deployed to prod, but never fully adopted. A couple of years later, there were new requirements and changes needed to make it usable. Upgrading this service gave me an ah-ha moment regarding types of dependencies and the level of upgrade risk they bring with them. After glancing at the original state of the service, here were my goals: Upgrade Spring Boot 2.0.6 to 3.1.x, Java 8 to 17, remove unofficial 
<a href="https://github.com/derjust/spring-data-dynamodb" target="_blank" rel="noopener">spring-data-dynamodb.</a>
, and upgrade AWS Java SDK v1 to v2. There wasn&rsquo;t any issue with AWS SDK v1, but I wanted some experience with v2 since that&rsquo;s what we&rsquo;ll be using for net-new services.</p>
<p>Only after I had started bumping Spring Boot versions did I realize that the unofficial Spring Boot DynamoDB dependency was last released in January of 2019 (four and a half years ago.) That release only supported up to Spring Boot 2.1. 
<a href="https://docs.spring.io/spring-boot/docs/2.5.x/reference/html/getting-started.html#getting-started.system-requirements" target="_blank" rel="noopener">Spring Boot 2.5</a>
 was the first release to support Java 17. The upgrade path would have been to remove Spring Data DynamoDB, upgrade to Spring Boot 2.5, Java 17, Spring Boot 3.1. Along the way would have been a Junit 4 to 5 migration and SpringFox to 
<a href="https://springdoc.org/" target="_blank" rel="noopener">SpringDoc.</a>
 The code had a good bit of extra dependencies, boilerplate copy/paste servlet filters and loggers, etc. All those together led me to write a minimal service from scratch on Spring Boot 3.1 and Java 17.</p>
<p>I utilized MapStruct to map between the API data format of shared properties + overrides and the denormalized set of records in DynamoDB. I wanted to do as much as possible with immutable Java records instead of Lombok-annotated data classes. The DynamoDB enhanced client came through and was compatible with Records following the same pattern 
<a href="https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/ddb-en-client-use-immut.html" target="_blank" rel="noopener">this documentation</a>
 shows with classes.</p>
<h2 id="the-code">The Code</h2>
<p><strong>DynamoDB mapper immutable entity</strong></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="line"><span class="cl"><span class="nd">@DynamoDbImmutable</span><span class="p">(</span><span class="n">builder</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">DemoEntity</span><span class="p">.</span><span class="na">DemoEntityBuilder</span><span class="p">.</span><span class="na">class</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nd">@Builder</span><span class="p">(</span><span class="n">toBuilder</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="kd">public</span><span class="w"> </span><span class="kd">record</span> <span class="nc">DemoEntity</span><span class="p">(</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// keys and special DynamoDB attributes</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@DynamoDbPartitionKey</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="n">pk</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@DynamoDbSortKey</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="n">sk</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@DynamoDbVersionAttribute</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">Long</span><span class="w"> </span><span class="n">version</span><span class="p">,</span><span class="w"> </span><span class="c1">// record level lock</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// record attributes</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="n">shared_attribute_one</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="n">shared_attribute_two</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="n">shared_attribute_three</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="n">override_attribute_one</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="n">override_attribute_two</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="p">}</span><span class="w">
</span></span></span></code></pre></td></tr></table>
</div>
</div><p><strong>DTO to entity mapper</strong></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="line"><span class="cl"><span class="nd">@Mapper</span><span class="p">(</span><span class="n">componentModel</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;spring&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="kd">public</span><span class="w"> </span><span class="kd">interface</span> <span class="nc">RootMapper</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="cm">/**
</span></span></span><span class="line"><span class="cl"><span class="cm">     * Singleton mapper, combine root level parameters with leaf level parameters.
</span></span></span><span class="line"><span class="cl"><span class="cm">     */</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// keys</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Mapping</span><span class="p">(</span><span class="n">source</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;root.id&#34;</span><span class="p">,</span><span class="w"> </span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;pk&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Mapping</span><span class="p">(</span><span class="n">expression</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;java(\&#34;SORT_KEY_PREFIX#\&#34; + leaf.leafType())&#34;</span><span class="p">,</span><span class="w"> </span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;sk&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// root level attributes</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Mapping</span><span class="p">(</span><span class="n">source</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;root.sharedAttributeOne&#34;</span><span class="p">,</span><span class="w"> </span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;shared_attribute_one&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Mapping</span><span class="p">(</span><span class="n">source</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;root.sharedAttributeTwo&#34;</span><span class="p">,</span><span class="w"> </span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;shared_attribute_two&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Mapping</span><span class="p">(</span><span class="n">source</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;root.sharedAttributeThree&#34;</span><span class="p">,</span><span class="w"> </span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;shared_attribute_three&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// leaf level attributes</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Mapping</span><span class="p">(</span><span class="n">source</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;leaf.overrideAttributeOne&#34;</span><span class="p">,</span><span class="w"> </span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;override_attribute_one&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Mapping</span><span class="p">(</span><span class="n">source</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;leaf.overrideAttributeTwo&#34;</span><span class="p">,</span><span class="w"> </span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#34;override_attribute_two&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">DemoEntity</span><span class="w"> </span><span class="nf">dtoToEntitySingle</span><span class="p">(</span><span class="n">Root</span><span class="w"> </span><span class="n">root</span><span class="p">,</span><span class="w"> </span><span class="n">Leaf</span><span class="w"> </span><span class="n">leaf</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="cm">/**
</span></span></span><span class="line"><span class="cl"><span class="cm">     * Combine the root level parameters with leaf level parameters.
</span></span></span><span class="line"><span class="cl"><span class="cm">     * Pass combo to MapStruct mapper that just has to worry about the singleton case.
</span></span></span><span class="line"><span class="cl"><span class="cm">     */</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">default</span><span class="w"> </span><span class="n">List</span><span class="o">&lt;</span><span class="n">DemoEntity</span><span class="o">&gt;</span><span class="w"> </span><span class="nf">dtoToEntityList</span><span class="p">(</span><span class="n">Root</span><span class="w"> </span><span class="n">root</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">root</span><span class="p">.</span><span class="na">leaves</span><span class="p">().</span><span class="na">stream</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                </span><span class="p">.</span><span class="na">map</span><span class="p">(</span><span class="n">leaf</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">dtoToEntitySingle</span><span class="p">(</span><span class="n">root</span><span class="p">,</span><span class="w"> </span><span class="n">leaf</span><span class="p">))</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                </span><span class="p">.</span><span class="na">toList</span><span class="p">();</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="p">}</span><span class="w">
</span></span></span></code></pre></td></tr></table>
</div>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Hammock Driven Development</title>
      <link>https://blog.danieladamstech.com/2023/hammock-driven-development/</link>
      <pubDate>Tue, 26 Sep 2023 03:45:00 -0400</pubDate>
      <guid>https://blog.danieladamstech.com/2023/hammock-driven-development/</guid>
      <description>&amp;hellip;Or how good ideas sometimes come in the middle of the night.
An episode of the Big Ideas in App Architecture podcast introduced me to a set of talks by Rich Hickey. I think it was this one with Joe Lynch? Rich&amp;rsquo;s talks were Simple Made Easy and Hammock Driven Development . Both were insightful regarding what mindset to invoke when creating software.
The premise of hammock driven development is that thinking about a topic over a long enough period of linear time causes the subconscious mind to prioritize it.</description>
      <content:encoded><![CDATA[<p><em>&hellip;Or how good ideas sometimes come in the middle of the night.</em></p>
<p>An episode of the Big Ideas in App Architecture podcast introduced me to a set of talks by Rich Hickey. I think it was 
<a href="https://www.cockroachlabs.com/big-ideas-podcast/joe-lynch/" target="_blank" rel="noopener">this one with Joe Lynch?</a>
 Rich&rsquo;s talks were 
<a href="https://www.youtube.com/watch?v=SxdOUGdseq4" target="_blank" rel="noopener">Simple Made Easy</a>
 and 
<a href="https://www.youtube.com/watch?v=f84n5oFoZBc" target="_blank" rel="noopener">Hammock Driven Development</a>
. Both were insightful regarding what mindset to invoke when creating software.</p>
<p>The premise of hammock driven development is that thinking about a topic over a long enough period of linear time causes the subconscious mind to prioritize it. Prefer a week or more in the conscious thought space; it won&rsquo;t happen with cramming for a day or two. That conscious prioritization lets your mind know it is something you want it to work on in the background. That can lead to an aha moment when you&rsquo;re not expecting it. An implication of the timeline is that you should start thinking about projects and problems on the horizon with a good bit of lead time before you need to implement a solution. This will give you enough time to really digest the options. Who knows, this could all be a 
<a href="https://dictionary.cambridge.org/us/dictionary/english/hooey" target="_blank" rel="noopener">bunch of hooey.</a>
</p>
<p>I tend to do my best thinking in the morning before the kids get up and before coming into the office since the house is quiet. I was one of those college students who would use the quiet study zone in the library to do my math homework. Today, I woke up at 3:45 with a generic idea of how the API I was trying to refactor could interact in a generic way with the data mapper to denormalize into the desired DynamoDB object structure. I thought through this from 3:45 to 4:30 and took some notes. Then I tried to go back to sleep, but unfortunately, that didn&rsquo;t work out. :P</p>
<p>The goal in modeling this API as defaults + overrides is gaining the ability to recategorize properties in the future between shared and specific to a service type.</p>
<h2 id="data-service-notes">Data Service Notes</h2>
<pre tabindex="0"><code>Record leaf(props...)
Record root(List&lt;leaf+string serviceType&gt; serviceTypes, props...) extends leaf

map(leaf, root) {
prop = coalesce(leaf, root)
return transform(prop)
}

root: ProfileConfig
leaf: ProfileServiceTypeConfig
</code></pre><p>
<a href="https://www.reddit.com/r/java/comments/nh34k3/why_are_records_not_extensible/gyv0kj3/" target="_blank" rel="noopener">Reddit link on why Java Records are not extensible:</a>
</p>
<blockquote>
<p>The restrictions on records may seem arbitrary at first, but they all stem from a common goal, which we can summarize as &ldquo;records are the state, the whole state, and nothing but the state.&rdquo; Specifically, we want equality of records to be derived from the entirety of the state declared in the state description, and nothing else. Were mutable fields, or extra fields, or superclasses permitted, these would each introduce situations where equality of records either ignored certain state components (it is questionable to include mutable components in equality calculations), or was dependent on additional state that is not part of the state description (such as additional instance fields or superclass state). This would have greatly complicated the feature (since surely developers would demand the ability to separately specify which components are part of the equality calculation), and also undermine desirable semantic invariants (such as: extracting the state and constructing a new record from the resulting values should result in a record equal to the original).</p>
</blockquote>
<p>Pivot to more static, less dynamic:</p>
<p><code>It will probably be easier to validate required fields through annotations if they are statically either in root or leaf. The same 400 status code could be returned with a custom exception during data mapping, but then lose the automatic spring boot validation root cause analysis in RFC ProblemDetail error returned.</code></p>
<p><code>It's still an easy mapping change to move a property from one to the other. Also solves the read structure (knowing which properties to include at the root vs. leaf level) without reflection.</code></p>
<h2 id="rest-of-the-morning">Rest of the Morning</h2>
<ol>
<li>Bible reading</li>
<li>Pushups and dumbbell rows listening to Morse code (
<a href="https://streammyaudio.com/archive" target="_blank" rel="noopener">CRSnet streams</a>
)</li>
<li>Yogurt and nuts listening to the 
<a href="https://www.youtube.com/@allin" target="_blank" rel="noopener">All-In podcast</a>
</li>
<li>Shower and developing the idea for this blog post</li>
<li>Writing blog post</li>
<li>Planning on hitting Chick-fil-A for a chicken biscuit for second breakfast on the way in to work.</li>
</ol>
]]></content:encoded>
    </item>
  </channel>
</rss>
