<?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[Mothership - Medium]]></title>
        <description><![CDATA[Product &amp; Engineering Blog - Medium]]></description>
        <link>https://medium.com/mothership?source=rss----f78799e32fc1---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Mothership - Medium</title>
            <link>https://medium.com/mothership?source=rss----f78799e32fc1---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 13:01:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/mothership" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[GraphQL at Mothership]]></title>
            <link>https://medium.com/mothership/graphql-at-mothership-1df6402cc435?source=rss----f78799e32fc1---4</link>
            <guid isPermaLink="false">https://medium.com/p/1df6402cc435</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[Justin Dao]]></dc:creator>
            <pubDate>Fri, 03 Jun 2022 09:02:45 GMT</pubDate>
            <atom:updated>2022-06-03T09:02:41.889Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>As with many startups, our company began on top of a monolithic backend. This worked for quite a while, but as Mothership grew, we came to realize this was not maintainable in the long run. Shipments, quotes, invoices, and routes are just some of the many entities our system deals with on a daily basis, and having these all maintained by the same service was rapidly leading to a massive, brittle, and hard-to-change application. So we began the process of splitting up our backends into microservices, each with their own domain area boundaries.</p><p>However, our frontends still rely on having access to all of these different data. Microservices are wonderful from a backend perspective, since they only need to deal with their own domain and not be overloaded with code they don’t care about. But exposing all of this data to the frontends can be pretty difficult. We didn’t want to generate significantly more traffic from our frontend clients by calling out to all of these microservices, and we needed to move on from the previous monolith.</p><h3>Creating a GraphQL BFF</h3><p>With GraphQL, we can provide a flexible <a href="https://samnewman.io/patterns/architectural/bff/">Backend-for-Frontend</a> (BFF) API solution to any of our frontends while still reaping the benefits of microservices. GraphQL puts the onus on the caller to provide the desired response schema, so we can customize our BFF to only call the required services for the requested data. Don’t need the quote associated with a shipment? Our GraphQL endpoint doesn’t need to query our quote microservice. Need all the possible data for a given invoice? Awesome, our GraphQL API can provide a single endpoint for you to use to fetch those data!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*j4HvdtGYYde2P8WSKCjygg.png" /></figure><p>New tech is always a bit intensive to incorporate into an existing stack, but the benefits far outweighed the effort we had to put in. We’re not planning to go in depth about the benefits and drawbacks of GraphQL (if you want to learn more, we really like this <a href="https://medium.com/the-programmer/rest-api-vs-graphql-fetch-what-you-want-a7c96c446dbf">overview</a> on the topic), but instead talk about Mothership’s GraphQL usage, and the knowledge we have gained from traversing down this path.</p><h3>Our Initial Approach</h3><p>Here at Mothership, most of our API backends are hosted using <a href="https://expressjs.com/">Express</a>. We did not want to deviate too far from this, so it is no surprise we landed on <a href="https://www.npmjs.com/package/express-graphql">express-graphql</a> to begin our GraphQL journey.</p><p>We wanted the organization of the GraphQL-based BFF to mirror the organization of our microservices: a router to provide the main GraphQL endpoint, and then have logic organized by each entity or microservice that could be used throughout the API. Since multiple teams would be updating and maintaining this code, we needed to ensure it was as straightforward as possible, while still providing optimal performance in our queries.</p><p>The initial approach consisted of a simple GraphQLRouter.ts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8919c301bcda7eed6015462e3147a380/href">https://medium.com/media/8919c301bcda7eed6015462e3147a380/href</a></iframe><p>Then in our services, we would create a pretty straightforward GraphQL Schema file in schema.gql and pass it into the router:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14daf93dafcd1963e228a3cf56343b69/href">https://medium.com/media/14daf93dafcd1963e228a3cf56343b69/href</a></iframe><p>We then populated the rootValue in the Route with our method names that matched our GraphQL schema. However, this means all of the logic had to be in one large GraphQLRouter. Splitting our logic up by entity type seemed like a logical next step. In order to achieve this, we created a concept of a GraphQLManager.ts , which would provide its own instance of queries, mutations, and a schema.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb1e37d92a5ff6a3d1d2392288e1feca/href">https://medium.com/media/eb1e37d92a5ff6a3d1d2392288e1feca/href</a></iframe><p>And our updated GraphQLRouter.ts :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b97a8e690c88a627f20dc5c68279eae/href">https://medium.com/media/7b97a8e690c88a627f20dc5c68279eae/href</a></iframe><p>And now, this allows us to split up our logic into concrete entities.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9462eba414696f4cd5499001e0a689ba/href">https://medium.com/media/9462eba414696f4cd5499001e0a689ba/href</a></iframe><p>This implementation worked for a while, but there were a few hiccups along the way:</p><ul><li>What if two separate managers implemented a query with the same name (i.e. two fetchShipment methods)? We ended up implementing some cumbersome validation code in the constructor of the GraphQLRouter to validate this.</li><li>Another nuisance was managing the GraphQL schema to be up to date with our typescript types libraries.<br>– Here at Mothership, each microservice exposes a -types npm package that contains all of the TypeScript interfaces that can be used by other services. Whenever a type needs to be updated, we release a new version of the types package alongside each microservice update.<br>– Since we are manually defining the GraphQL Schemas in this service, we would need to update these schema files manually every time there is a types package version bump.</li><li>The largest pain point arose when we wanted to start implementing field resolvers. As it turns out, the default <a href="https://www.npmjs.com/package/graphql">graphql</a> buildSchema function <a href="https://stackoverflow.com/questions/53984094/notable-differences-between-buildschema-and-graphqlschema"><strong>does not support this</strong></a>. We did have a short burst effort where we updated our GraphQLManager to take in a typeResolvers property, and switched to makeExecutableSchema from <a href="https://www.npmjs.com/package/@graphql-tools/schema">@graphql-tools/schema</a>, but this still didn&#39;t feel like the correct solution.</li></ul><p>Given that this isn’t the end of the post, you might have already realized that this implementation didn’t stick around.</p><p>As programmers tend to do when having to do tedious tasks, we wondered if there was a cleaner, easier, and more maintainable solution to our GraphQL problems…</p><h3>Enter TypeGraphQL</h3><p><a href="https://typegraphql.com/">TypeGraphQL</a> is a framework designed to work well with standard Typescript practices, and utilizes <a href="https://www.typescriptlang.org/docs/handbook/decorators.html">Typescript Decorators</a> to apply specific GraphQL logic. We discovered this framework through our woes with dealing with the field resolver implementations, and it has truly helped us remove some of the original drawbacks of integrating GraphQL into our systems.</p><h4>No more manual GraphQL Schemas!</h4><p>First and foremost, TypeGraphQL has completely removed our need to manually define our GraphQL schemas. Instead, we now rely on these decorators, and it generates it for us, completely abstracting it away. Let’s take a look at our typing for Shipment.ts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0083fb200de7da18dded042a1576352/href">https://medium.com/media/a0083fb200de7da18dded042a1576352/href</a></iframe><p>Previously, anytime we had to update our InternalShipment here, we would need to make a manual change to our GraphQL schema. Now, we just need to update this class definition with the appropriate decorators!</p><p>Another problem this helps us solve is ensuring our GraphQL schemas remain up to date. Previously, it was possible for us to bump our types versions, but forget to update the GraphQL schema. This would mean the GraphQL library would not be updated to return those data to a possible expecting client.</p><p>To illustrate, suppose an update to our accounting service is needed. You update the types library, bump the version in the GraphQL service, everything builds fine, and you deploy. An hour later, you realize the Finance team is running around with their hair on fire because nobody can submit invoices through the dashboard anymore, since the field is missing from the GraphQL schema.</p><p>With TypeGraphQL, we can ensure that all fields on our InternalShipment are always up to date with the installed types version, since we are implementing that interface!</p><h4>More easily maintainable Managers!</h4><p>TypeGraphQL also provides a very clean and readable way to implement the kind of “entity manager” concept that works will with our microservices.</p><p>Here is our updated ShipmentResolver.ts (renamed from ShipmentManager):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd0c0e75d72eb1e39255123d315b0fb9/href">https://medium.com/media/bd0c0e75d72eb1e39255123d315b0fb9/href</a></iframe><p>You can see that it is very clear what functions the Queries, Mutations, and FieldResolvers are, and you can see at a glance what each method accepts and returns.</p><p>With TypeGraphQL, its buildSchema method pushes the schema implementation to the service itself:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87f134dc585e2597f13dc74f42ac9941/href">https://medium.com/media/87f134dc585e2597f13dc74f42ac9941/href</a></iframe><p>Which means our GraphQLRouter code gets updated to become super barebones:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be0b8df33998398fe48b90c7db1edbb2/href">https://medium.com/media/be0b8df33998398fe48b90c7db1edbb2/href</a></iframe><p>In addition, TypeGraphQL also handles the duplicate method issue discussed above for us!</p><h4>Drawbacks</h4><p>This seems like the perfect solution, but TypeGraphQL isn’t without a couple (albeit small) drawbacks.</p><p>The main one seen above is that it requires services to “redefine” these typescript interfaces exported by our microservices’ types libraries. However, the benefit of using this library far outweighs this drawback, given we have a way to couple these together through interface implements.</p><p>Another small drawback for us is that TypeGraphQL, at the time of this post, relies on the previous version of GraphQL 15.8.0. GraphQL 16 does bring some cool features (such as <a href="https://github.com/graphql/graphql-js/pull/3259">better error messages</a>), and fortunately, TypeGraphQL is <a href="https://github.com/MichalLytek/type-graphql/issues/1100">working to update their support here</a>.</p><h3>Conclusion</h3><p>Using GraphQL has been great for us to grow as developers, forcing us to think outside of the standard REST design patterns. We were able to create a service that fulfills our frontend needs, is easily maintainable by multiple teams, and is able to reap the benefits of microservices, all while still following our company’s standard engineering design.</p><p>You may find at your company that as you start building out microservices, you need to create a similar solution. Hopefully this insight into Mothership’s GraphQL solution might give you some new ideas to explore. I’m sure this isn’t the end of our foray into GraphQL, and we look forward to sharing other learnings in the future.</p><p>If you like what you see and want to help Mothership expand its GraphQL infrastructure (or any of our other exciting projects), <a href="https://www.mothership.com/careers">come work with us</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1df6402cc435" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mothership/graphql-at-mothership-1df6402cc435">GraphQL at Mothership</a> was originally published in <a href="https://medium.com/mothership">Mothership</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hey! We Found a Use for Quadtrees!]]></title>
            <link>https://medium.com/mothership/hey-we-found-a-use-for-quadtrees-759e9bca8abc?source=rss----f78799e32fc1---4</link>
            <guid isPermaLink="false">https://medium.com/p/759e9bca8abc</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Trenton Lawrence]]></dc:creator>
            <pubDate>Thu, 12 May 2022 00:26:39 GMT</pubDate>
            <atom:updated>2022-05-14T03:21:22.043Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sub-millisecond Timezone Resolution</h3><p>Mothership is modernizing the freight industry, which means we have to consider geography in many areas of our platform. We’ve relied heavily on the Google Maps Platform to build out our product, but have been shifting to open source or in-house solutions as we grow.</p><p>While this may sound crazy on the surface, there are a number of reasons to move these services in-house:</p><ul><li>Costs as we grow</li><li>Fine-tune results to fit our business needs</li><li>De-risk the business (We can scale location services to meet our needs and not worry about negotiating rate limits, etc.)</li><li>Build in-house expertise</li></ul><p>Today we’ll be looking at how we replaced Google’s Time Zone API in our stack.</p><h3>The Setup</h3><p>Much like replacing the parts of an airplane while it’s in flight, we need to be confident in the accuracy and performance of any homegrown solutions before we cut traffic away from Google. At the same time, we still want to centralize all of our time zone lookups across our services, giving us a single point to strangle away our calls upstream.</p><p>The first step was to design a simplified interface that worked for all of our existing time zone lookups. While Google’s Time Zone API isn’t a huge surface area, it does cover more than we need, like historical lookups. Since we don’t deal with dates in the past, our interface really just needs to return the current time zone identifier — such as America/Los_Angeles or America/Chicago—provided a pair of coordinates.</p><p>This turned out to be an embarrassingly simple API: a single POST endpoint that takes in coordinates and returns a timezoneId. Consider this example where we wish to resolve the time zone of coordinates for the town of Random Lake, Wisconsin.</p><pre>POST /timezone<br>{<br>    &quot;coordinates&quot;: {<br>        &quot;latitude&quot;: &quot;43.5554306&quot;,<br>        &quot;longitude&quot;: &quot;-87.9656231&quot;<br>    }<br>}<br><br>200 OK<br>{<br>    &quot;timezoneId&quot;: &quot;America/Chicago&quot;<br>}</pre><p>The next step was to build a new service to satisfy this interface where we proxied these requests upstream. Instead of each service calling Google’s APIs directly, we would proxy the request through this new service, where we could collect performance and accuracy metrics. This in-cluster proxy would add very little overhead to the overall latency, and we could be confident that we didn’t lose any accuracy as the data was still coming from Google.</p><figure><img alt="A diagram showing the differences before and after we added the Time Zone API to our stack. The before diagram shows three services calling Google. The second diagram shows three services calling our Time Zone API, which then calls Google." src="https://cdn-images-1.medium.com/max/1024/1*1BzNGrWH6rfxpG_AX537Ew.png" /></figure><p>Once we had all time zone lookups running through our new API, we could start experimenting with in-house solutions. While we would continue to use Google’s API for the response we returned to the caller, we could also call our own solution(s) in parallel and collect metrics. Before we could comfortably switch away from Google, we wanted to know that our average latency, error rate (failed lookups), and accuracy rate (did our result match theirs?) were within acceptable levels.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1249c8a8dea330d86cfea7b53ea2919/href">https://medium.com/media/e1249c8a8dea330d86cfea7b53ea2919/href</a></iframe><h3>The Strategy</h3><p>While we were in the design phase, we stumbled upon the open-source project <a href="https://github.com/evansiroky/timezone-boundary-builder">timezone-boundary-builder</a>. This project provides <a href="https://geojson.org/">GeoJSON</a> files of the current time zone boundaries from OpenStreetMap data.</p><p>The dataset was just a collection of GeoJSON “Features” that identified each time zone. Features are just JSON objects with some metadata (properties) tied to some geometry like points, lines, polygons and more. For example:</p><pre>{<br>  &quot;type&quot;: &quot;Feature&quot;,<br>  &quot;geometry&quot;: {<br>    &quot;type&quot;: &quot;Point&quot;,<br>    &quot;coordinates&quot;: [125.6, 10.1]<br>  },<br>  &quot;properties&quot;: {<br>    &quot;name&quot;: &quot;Dinagat Islands&quot;<br>  }<br>}</pre><p>Armed with a dataset and a dream, we began building out some methods for resolving a time zone from some coordinates.</p><h3>The First Attempt</h3><p>Since the dataset is packaged as an array of polygons, the simplest approach would have us iterate over the array and perform a <a href="https://observablehq.com/@tmcw/understanding-point-in-polygon">point-in-polygon check </a>on each time zone until we found one that contained our coordinates.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmothershipper%2Fembed%2Fpreview%2FRwxXgNE%3Fdefault-tabs%3Djs%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DRwxXgNE&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fmothershipper%2Fpen%2FRwxXgNE&amp;image=https%3A%2F%2Fshots.codepen.io%2Fmothershipper%2Fpen%2FRwxXgNE-512.jpg%3Fversion%3D1651798511&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f0f289dd6de719689b5138c239b5986/href">https://medium.com/media/6f0f289dd6de719689b5138c239b5986/href</a></iframe><p>Since point-in-polygon is an O(N) operation with regards to the number of points, we knew this could get expensive fast. The time zone polygons are complex shapes (the Los Angeles time zone polygon contains 28,265 points), so we opted to first check whether or not the point was in the polygon’s bounding box. This turned it into an O(4) constant-time bounds check before running the more expensive point-in-polygon check.</p><figure><img alt="A comparison of shape complexity, showing a bounding box around a polygon (the Los Angeles time zone)" src="https://cdn-images-1.medium.com/max/1024/1*jv0VBfSNg1kNI7Mn-bYJYw.png" /><figcaption>There’s a huge difference in point count between the Los Angeles time zone and its bounding box</figcaption></figure><p>We suspected this approach might yield “good enough” performance, as most time zones would get rejected with the cheaper bounds check.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pAJC8bvKJNlWfrMA47gEUg.png" /><figcaption>A graph of response times, comparing Google’s Time Zone API and our brute-force implementation</figcaption></figure><p>The performance metrics showed that we were faster than Google’s Time Zone API on average, though we know that’s a result of network latency. Given an <a href="https://colin-scott.github.io/personal_website/research/interactive_latency.html">upper bound of ~150 ms</a> for round-trip time and lower bound of ~10ms (ping from within our cluster), it seems reasonable to believe most of that 57.5ms average is spent on the network. While serviceable, our first approach was slower than expected and we knew we could do better.</p><h3>A New Challenger Approaches</h3><p>Our next attempt incorporated a type of data structure called a <a href="https://en.wikipedia.org/wiki/Quadtree">quadtree</a>. There are a few flavors/variations, but in general a quadtree’s nodes each have exactly four children or no children at all. We’ve used a region quadtree, which when applied to a two-dimensional space, each node in the tree represents a region of space, with the child nodes representing sub-divisions, i.e. the north-west, north-east, south-west and south-east quadrants.</p><p>When you look at a map of the world, it becomes apparent that we could divide it into four quadrants and guide our search by only checking polygons that fall into the same region as our point. If we repeat the subdivision process a few times, it could filter out most polygons that we’d have to check.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MqB-bJaDhhF3vAPgjfeRog.png" /><figcaption>The world’s time zones (blue) overlaid on the world’s countries (white)</figcaption></figure><p>Quadtrees are <a href="https://jimkang.com/quadtreevis/">commonly used with points</a>, but our dataset contains polygons. To get them into the tree, we check if the polygon can fit entirely within the region covered by the node. If the polygon crosses a node’s boundary, we leave the polygon in the parent node. Once a node collects enough polygons, we attempt to split it into four children and redistribute the polygons amongst them.</p><p>Here’s what our tree looks like when rendered over our time zone data set:</p><figure><img alt="A quadtree overlaid atop the world’s time zones and countries" src="https://cdn-images-1.medium.com/max/1024/1*v0rj_WuSPmVBDw33YIxG3Q.png" /><figcaption>The number of timezones (blue) contained in each node (red) drastically reduces at greater depths</figcaption></figure><p>As we learned previously, polygons are complicated shapes and expensive to work with, so our tree uses the polygon’s bounding box for the indexing. This also helps with search performance as checking if a point is inside of a rectangle is much faster than checking if a point is inside of a polygon.</p><p>Searching the tree starts at the root and identifies which child node contains our point. We then visit that quadrant (node) and repeat the process until we’re at a leaf node that contains our point (think depth-first search). At the leaf node, we check each stored polygon to see if our point is contained within its bounding box. If not, we work our way back up the tree and check the polygons stored in the parent nodes along the way.</p><p>Here’s that process visualized when resolving the time zone for Louisville, Kentucky:</p><figure><img alt="A gif showing the navigation of the quadtree’s node structure when looking for Louisville Kentucky" src="https://cdn-images-1.medium.com/max/1024/1*Fm_yR58J-exnuyRASJDB_w.gif" /><figcaption>The quadtree is pretty quick at narrowing down the search space</figcaption></figure><p>The quadtree approach let us rule out a lot of the time zone boundaries up front. For example, when searching for a location in Los Angeles, the brute force approach had to check 131 boundaries, where the quadtree only checked 13 bounding boxes and 1 polygon.</p><p>The performance of our quadtree ended up being better than we expected, and more than sufficient for our needs. At an average of 1.3ms, with the max around 5ms, we were in the territory of being better than Google’s Time Zone API.</p><figure><img alt="A graph of response times, comparing the bruteforce and quadtree implementations" src="https://cdn-images-1.medium.com/max/1024/1*N0FW0MZ9Log--8snafTsoA.png" /><figcaption>Quadtree is clearly significantly faster than the bruteforce implementation</figcaption></figure><h3>Is There A Better Tree?</h3><p>This isn’t quite the end of the story as we also explored a different kind of tree structure — the <a href="https://en.wikipedia.org/wiki/R-tree">R-tree</a>. Our dataset is mostly large polygons which limits our ability to redistribute them across child nodes in our tree. In effect, this creates a very top-heavy tree. We hypothesized that since R-trees are balanced, we’d see faster/more consistent search times.</p><p>Performance was similar to using a quadtree, but the R-tree didn’t seem to perform any better on average. We suspect this is because our bounds checks are cheaper than tree traversal, and the number of polygons in the dataset isn’t large enough to allow for the balancing to really help. The details of an R-tree aren’t the focus of this post, but if you’d like to read more <a href="http://www.gitta.info/SpatPartitio/en/html/ObjOriDecomp_learningObject2.html">here’s a good article on the topic</a>.</p><figure><img alt="A graph of response times, comparing the quadtree and R-tree implementations." src="https://cdn-images-1.medium.com/max/1024/1*lVdOYxHGiYNaHcgCseaZyg.png" /><figcaption>It’s quite difficult to see any significant difference between the two implementations.</figcaption></figure><p>In the end, we opted to use the quadtree implementation in production. However, we wouldn’t have known it was the most suitable solution for us if we hadn’t measured the performance. When we get some more time, we’d like to explore what would happen if we broke up the dataset into smaller polygons to confirm our suspicions.</p><h3>On Accuracy</h3><p>We discussed performance metrics as we explored the various implementations we tested, but we didn’t touch on accuracy and error metrics. The accuracy and error metrics allowed us to validate the dataset we found, but had little bearing on the approach we used to resolve the time zone. For example, both the quadtree and brute force approach return the same result from our dataset — the latter just being slower than the former.</p><p>That said, we did notice some differences between our dataset and the results from Google. Theirs seemed to be fairly accurate, and in the worst case defaulted to the <em>legally observed</em> time zone. For our purposes though, we’re interested in the time zone used by humans in the region, legality be damned.</p><p>As it happens, Phenix, Alabama <a href="https://en.wikipedia.org/wiki/Phenix_City,_Alabama#Time_zone">falls within the geographic bounds of the Central time zone but observes Eastern time</a>. Google reports Phenix as observing Central time, and the dataset we use has Phenix recorded as within the Eastern time zone. On the other hand, the towns of Mountain City, Jackpot, Jarbidge, and Owyhee in Nevada are <a href="https://en.wikipedia.org/wiki/Jackpot,_Nevada">legally in the Pacific time zone but observe Mountain time</a>. Google reports this correctly, but our dataset has these cities in the Pacific zone.</p><p>While some of these towns are very sparsely populated (Mountain City is even considered a ghost town) and not likely going to cause an issue for us, we added the ability to adjust our results to more accurately reflect the locally observed time zones should the need arise.</p><p>It’s also worth mentioning that we operate primarily in the contiguous United States, so our accuracy results are not likely representative of the entirety of either dataset. Similarly, the differences we detected do not mean Google’s data is wrong or that our dataset is any more or less accurate, we just thought these were fun edge cases worth calling out.</p><h3>We’re Hiring!</h3><p>We mentioned we’re building our in-house expertise so we can implement new usages of location services in our product. We also want to tailor these services to better fit the needs of the trucking industry — services as common as navigation have different considerations for truckers than they do consumer vehicles.</p><p>There’s a lot more work to be done in this area. Some of the projects we’d like to tackle in the next year</p><ul><li>Using historical shipment and driver density to better predict demand and preemptively direct carriers to areas with more opportunity</li><li>Bring navigation/direction services in-house and improve estimated travel time calculations</li><li>Address geocoding and autocompletion services</li><li>Add more geofenced features to our carrier mobile app</li><li>Improve our machine learning powered shipment dispatching and route optimization processes</li></ul><p>We could use all the help we can get. If you think quadtrees were the wrong choice and you could do better, you believe you could help us build any of the aforementioned features, or you just want to build things and write blog posts about them, <a href="https://www.mothership.com/careers">come work with us</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=759e9bca8abc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mothership/hey-we-found-a-use-for-quadtrees-759e9bca8abc">Hey! We Found a Use for Quadtrees!</a> was originally published in <a href="https://medium.com/mothership">Mothership</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Picking RIBs: State Management at Scale]]></title>
            <link>https://medium.com/mothership/picking-ribs-state-management-at-scale-968a20379ba?source=rss----f78799e32fc1---4</link>
            <guid isPermaLink="false">https://medium.com/p/968a20379ba</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Austin Odell]]></dc:creator>
            <pubDate>Tue, 10 May 2022 22:12:45 GMT</pubDate>
            <atom:updated>2022-05-10T22:12:45.574Z</atom:updated>
            <content:encoded><![CDATA[<p>Mothership’s Carrier application enables local truckers to earn more money by matching them with loads for delivery. The application is powered by real-time data and an always up-to-date carrier location. Running on real-time data provides a best-in-class experience, but is pretty complicated to build. How can an application’s state and UI remain in sync with a constant flow of new data?</p><p>Mothership had previously used a hybrid Android/iOS application, built using React Native. It was clear that by using a shared codebase, we were making it more difficult on ourselves, especially as it relates to handling real-time data. So, we made the decision to rewrite the application for both Android and iOS using their respective native development tools.</p><p>Starting from zero can be a bit daunting. Development with the Android SDK provides no shortage of architectures and frameworks that can be used to improve code function and quality. Making the initial decision of which architecture to follow is extremely important–making the wrong choice could lead to another rewrite in the close future or it could lead to overly complex code making it hard to ramp up new contributors. Let me walk you through the steps we took to ultimately make this choice.</p><h4><strong>The beginning</strong></h4><p>Much of our focus early on was on requirements gathering. Some of these included:</p><ul><li>If data is changed behind the scenes, the app should update immediately</li><li>When a carrier gets through our onboarding approval process, their status should update immediately in-app</li><li>If a customer requests a pallet moved, that request should show up without a refresh of the app</li><li>As the carrier drives their truck, our directions should update to reflect their current location</li></ul><p>Once we had all of the requirements clearly defined, we started investigating which architecture would best handle our needs, making the development process as easy as possible. The obvious choice at the time was MVVM; it’s a standard practice architecture utilized on both Android and iOS platforms.</p><h4><strong>MVVM</strong></h4><p>In the past, MVVM has traditionally been the ideal application architecture to use because it provides a clear separation of responsibilities and is somewhat easy to test. MVVM consists of a Model, View Model, and View, each with their own respective roles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9edtp6yOp65-8Psv.png" /></figure><p><strong>Model</strong> — The data layer of an application. It cannot talk to the View or View Model directly.</p><p><strong>View Model</strong> — The glue holding the Model and View together. It observes and manipulates data in the Model and uses listeners to update the View.</p><p><strong>View </strong>— The UI layer of an application. It observes properties on a View Model and updates based on those values.</p><p>MVVM overcomes many of the drawbacks of MVP, such as the tight coupling between the view and presenter. MVVM does this by providing a more efficient and less dependent way of bridging the data and UI layers together. This architecture works great for most applications; it provides a clearly defined structure enabling developers to write clean and testable code.</p><p>However, this architecture can be difficult to work with as your application grows in size, especially when the application is driven by a real-time stream of data that can completely change application state or UI. With Android, the preferred way of changing views is using a navigation graph, which means that you must define every fragment to fragment transition that can be made. If you are building an application with hundreds of views, this quickly becomes a difficult-to-maintain mess.</p><h4><strong>RIBs to the rescue</strong></h4><p>Uber’s application can do so many things, and it performs on a massive scale–handling thousands of possible states and views. Their engineering teams developed an architecture framework to tackle the exact same problem we encountered: reacting to real-time data in an efficient and non-complex way.</p><p>RIBs stands for Router, Interactor, Builder.</p><p><strong>Router</strong> — Responsible for attaching and detaching states and views. It is kept separate from the interactor to increase the testability of the interactor, reduce boilerplate keeping the interactor small, and keep parent and child interactors independent.</p><p><strong>Interactor</strong> — Responsible for all business logic and determining which states and views to attach.</p><p><strong>Builder</strong> — Responsible for constructing the router, interactor, view (if necessary), and all other state or view builders.</p><p>Using RIBs, your application code is structured like a tree. Every RIBs application has a root node, and from there, you traverse the tree with each node making its own decision of which child to attach next. There are two types of nodes, those with a view and those without. Those without a view are called an application state and those with a view are called a feature.</p><p>For example, our application uses a session repository that has an observable session object that tracks various user details and their authentication state. Making this observable means that we are notified when session state changes. In the diagram below, you’ll see our application’s Root node and the 2 destination nodes we can go to. On application launch, the Root node is attached and immediately observes the session state. On any state change, this Root node will attach a child node, either LoggedIn or LoggedOut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8vLZpVur79b-dQC7.png" /></figure><p>In the above example, all nodes are non-view nodes. If you take a look below at a simplified version of our LoggedOut tree, the two child nodes are view nodes. In this simplified example, whenever the LoggedOut node is attached, it will immediately attach the Welcome node and display that view. The Welcome node provides a listener for its parent node to observe actions made, like button presses. When the login button is pressed, the LoggedOut node observer will react by attaching the Login node, replacing the view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-tkCP3PQIqZprtPC.png" /></figure><p>When the views are replaced, there is no need to define any navigation actions because we no longer need to explicitly manage a navigation graph–our RIBs tree gives this for free as a function of application state changing! This drastically reduces complexity of the application because each node has a single responsibility; view nodes can focus on the UI provided by that node and non-view nodes can focus on the transitions between their direct children.</p><h4><strong>Conclusions</strong></h4><p>Bringing this back to state management, in the above examples, everything is driven by the real-time data available on the observable session state. Beyond just session state, our application has many other observable states we can use to drive navigation decisions. We can continue observing each of these states to traverse the LoggedIn tree to ensure a user’s onboarding requirements are met. What this means is if a user&#39;s insurance information were to expire, for example, their application would immediately take them to the ValidateInsurance node without any user interaction required or navigation actions defined, it just works!</p><p>This is just one simple example of how our real-time data controls what our application can do and display, and this control is handled entirely by business logic with views playing a very small role in the application as a whole.</p><p>It’s important to note that RIBs itself is not an architecture but rather a framework built around a pseudo-MVP architecture that solves the tight coupling problems of MVP. If you are building an application with large scale and real-time data, I highly recommend checking out RIBs to see if it’s right for you.</p><h4>What’s Next?</h4><p>Some of our next projects include migrating our iOS application from plain MVP to RIBs, start using Jetpack Compose on Android to generate our views, and moving all remaining REST calls to streaming data. If what we’re working on sounds interesting, <a href="https://www.mothership.com/careers">come work with us</a>!</p><p>For more information on RIBs, check out <a href="https://github.com/uber/RIBs">the github page</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=968a20379ba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mothership/picking-ribs-state-management-at-scale-968a20379ba">Picking RIBs: State Management at Scale</a> was originally published in <a href="https://medium.com/mothership">Mothership</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes, GitOps, and Odd Jobs]]></title>
            <link>https://medium.com/mothership/kubernetes-gitops-and-odd-jobs-671829e83c86?source=rss----f78799e32fc1---4</link>
            <guid isPermaLink="false">https://medium.com/p/671829e83c86</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Jack]]></dc:creator>
            <pubDate>Wed, 27 Apr 2022 03:34:34 GMT</pubDate>
            <atom:updated>2022-04-29T16:03:00.172Z</atom:updated>
            <content:encoded><![CDATA[<p>We love Kubernetes at Mothership, but one area we’ve found lacking is its ability to run one-off jobs. It’s not that Kubernetes can’t run one-off jobs — that’s why we have the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/">Job</a> resource after all — it’s that these one-off jobs don’t fit neatly into a GitOps deployment workflow.</p><h3>The GitOps Problem</h3><p><a href="https://about.gitlab.com/topics/gitops/">GitOps</a> works incredibly well for <em>slow-changing</em> or <em>persistent</em> state, but starts to fall apart when talking about <em>rapidly-changing</em> or <em>ephemeral</em> state.</p><figure><img alt="GitOps in a nutshell: updates in git trigger automation pipelines that ultimately update the runtime environment to match the source of truth." src="https://cdn-images-1.medium.com/max/1024/1*VTVJrnid362BegGM6wxYLw.png" /></figure><p>I like to think of GitOps as storing your ideal system state in git. The system may not always be able to reach the desired state, but the intention is there.</p><p>Let’s say I’m maintaining my service’s replica count in git — if I push a commit that scales that service to three replicas, I generally want the system to maintain three replicas until I push a change to scale it back down. A lack of compute resources or a crashed server doesn’t mean I want any less than my three replicas.</p><p>But in this example, we consider replica count to be <em>persistent</em> state. We have no requirement to change it frequently. Now imagine we want to scale throughout the day according to the load on the service. If we continue to think of replica count as <em>persistent</em> state, this would require close monitoring and pushing commits as the load changes.</p><p>If we reframe replica count as <em>ephemeral</em> state, we also want to reframe our ideal system state to make it work well in a GitOps model. Kubernetes gives us the <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/">HorizontalPodAutoscaler</a> which does just that. The configuration for our HPA becomes <em>persistent</em> state that we can manually manage, while replica count becomes <em>ephemeral </em>state managed by the controller.</p><h3>One-off Jobs</h3><p>Just like replica counts, one-off jobs fall into this category of <em>ephemeral</em> state. If I want to run a script to backfill a new database, I generally want it run once to completion and then never again. Once it completes, it no longer has a place in my ideal system state.</p><p>If I’m treating one-off jobs as <em>persistent</em> state, this means I have to go remove my job from git after it runs. If I forget to do this, this leads to two potential problems on the next commit: blocked deploys, or jobs running more than once. Nobody wants this kind of surprise when they’re trying to ship an unrelated/urgent bug-fix.</p><figure><img alt="The possible flows for a Kubernetes Job running twice, or blocking future deployments." src="https://cdn-images-1.medium.com/max/861/1*Can1okkN1ggIgiAGBB381Q.png" /><figcaption>Leaving a job checked in can block deployment pipelines, or cause it to run twice!</figcaption></figure><p>When we looked at how our developers were using jobs, we found most had the following in common:</p><ul><li>The job was truly single-use, backfilling a database or vendor, repairing data from a bug, etc.</li><li>The job was a custom script, but made use of the service’s type definitions and business logic</li><li>The job needed the same configuration/secrets as the service, or at least a subset of it</li></ul><p>In a way, most of this is already <em>persistent</em> state managed under GitOps — it’s the configuration and code that make up our Deployment in the first place. The <em>ephemeral</em> state is just the presence of the job in our cluster. In that case, we’d need some kind of controller to manage this state, creating jobs from deployments in the cluster on demand.</p><h3>OddJob: The Mothership Job Service</h3><p>That is, in a nutshell, what our job service does for us. OddJob is our solution to creating and running jobs in the cluster on demand. It can take an existing Deployment in our cluster, and build/deploy a usable Job manifest from it.</p><p>For the most part, this gives us the best of both worlds. Our engineers can write one-off tasks the same way they’d develop anything else. Their code will get reviewed, tested and deployed using the workflow they’re already familiar with — and there is no cleanup step or concern that their job will run twice. The difference is that we no longer use git to manage when a job is run, or the command run in the container.</p><p>Since it would be dangerous to let anybody create a job from any deployment, we let teams manage permissions through annotations on the resource. Service owners can opt-in to OddJob by adding annotations specifying which teams or users can create jobs for a their deployment. If no annotations are present on a given deployment, OddJob will ignore it and refuse to let anyone create a job from it.</p><figure><img alt="An allowed-teams / allowed-users annotation on the deployment dictates who can create jobs based on the deployment" src="https://cdn-images-1.medium.com/max/1024/1*mDGdjXtzMnJySQigB-V0Og.png" /><figcaption><em>These annotations on a deployment would allow our carrier and marketplace teams to create jobs from it.</em></figcaption></figure><p>OddJob logs every command that gets run and the user who ran it. While we trust our team and have a way to audit what has been run, it’s still more access to the cluster than we feel comfortable with in the long-run. A more ideal system would have a way to audit commands before they are run, rather than after. We have plans to revisit this soon, but decided we can live with this tradeoff while proving out the developer experience.</p><p>So what does this look like in action?</p><figure><img alt="Terminal recording showing our job service in action." src="https://cdn-images-1.medium.com/max/1024/1*TKVroEXj9L2QRvTV86QrlQ.gif" /></figure><h3>What’s next for OddJob?</h3><p>There are a few features we’d still like to add, but we’re either waiting on upgrades to our clusters, or more bandwidth. A few ideas that we’ve thrown around:</p><ul><li>Creating our own ‘Job’ CRD that lets us save a job template, including the job’s command. This would let the team review and pre-approve the commands being run in the containers. It would also let us cover jobs that need different settings (ex: more resources) than the deployment they’re based on.</li><li>Once we upgrade our cluster, we’ll have the <a href="https://kubernetes.io/blog/2021/04/12/introducing-suspended-jobs/">suspended job</a> feature. Using this, we could create a suspended job, then introduce a Slack approval workflow which would also let us audit commands before they’re run, as well as when they are run.</li><li>Maybe a stretch, but indexing the file paths in our container images. This would allow us to auto-complete paths to scripts or files, making it even easier for engineers to find the right path to their script in the container.</li><li>Open sourcing — this will come once we’ve tightened up our security model, cleaned up the code, and written ample instructions for deploying and running. But we’ve already seen a lot of value and think others might too!</li></ul><p><a href="https://mothership.com/careers">Come help us build it!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=671829e83c86" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mothership/kubernetes-gitops-and-odd-jobs-671829e83c86">Kubernetes, GitOps, and Odd Jobs</a> was originally published in <a href="https://medium.com/mothership">Mothership</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analytics Engineering at Mothership]]></title>
            <link>https://medium.com/mothership/analytics-engineering-at-mothership-8d061b66bec3?source=rss----f78799e32fc1---4</link>
            <guid isPermaLink="false">https://medium.com/p/8d061b66bec3</guid>
            <category><![CDATA[analytics-engineering]]></category>
            <category><![CDATA[data-warehouse]]></category>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Brian Wentz]]></dc:creator>
            <pubDate>Tue, 26 Apr 2022 16:37:48 GMT</pubDate>
            <atom:updated>2022-05-12T04:56:24.012Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Power of Data Modeling</h3><p>Right now is an exciting time to be part of a data team, and early-stage is always an exciting time to be part of a start-up. New tools in the Modern Data Stack made data modeling more dynamic and accessible, multiplying the potential impact of a small data team. A good data modeling process empowers the business to make data driven decisions, enables curated self-service and ensures scalability, reliability, and shared context. This post will talk about how we organize our analytics data processes, with a focus on the data modeling layer.</p><p>The workflows enabled by having analysts and analytics engineers own their own data models are meaningfully different from how most teams have worked until quite recently. In the past, data teams at start-ups have either had to build and maintain single-report queries with siloed and potentially brittle definitions, or else log requests to an engineering team backlog to execute data transformations in the ETL pipeline. By the time a data engineer is hired to standardize some centralized views the amount of technical debt and maintenance work is substantially painful (and expensive).</p><p>New technologies have granted data teams the power (and responsibility) to build their own flexible data models into a centralized codebase, allowing us to react quickly to changing products and take a new level of ownership of the data that we work with every day. At Mothership we primarily use an <a href="https://en.wikipedia.org/wiki/Extract,_load,_transform">ELT</a> process where data is extracted and loaded via <a href="https://fivetran.com/">Fivetran</a> and <a href="https://segment.com/">Segment</a>, then transformed and modeled in <a href="https://www.getdbt.com/product/what-is-dbt/">dbt</a>. Our BI tool is Looker, which primarily pulls directly from the modeled outputs rather than perform any significant calculations. In our analytics database we organize into distinct layers of ingestion where we clean and stage data, and then modeling where we do transformations, render metrics and develop models.</p><h3>How it Starts</h3><p>If you’ve been part of an early stage start-up you’ve seen this: someone (usually in engineering) has set up a simple iteration of a BI tool. Maybe it’s Metabase, maybe it’s Looker, but what tends to happen is that the BI tool sits directly on top of a replica of production data. When schemas are concise or for those close to the source data this can be a handy solution, but as more data sources are connected and more people get access to the BI tool you find a few key problems to solve:</p><ul><li>Difficulty in reproducing or interpreting metrics</li><li>Data structures that are difficult to align to business problems</li><li>Inflexibility and data silos</li><li>No formal data validation or testing</li><li>Minimal data governance or security</li></ul><p>All this impacts the company’s ability to leverage data efficiently and make informed decisions about the right problems. The solution here is a thoughtful approach to data modeling that can build a shared context for teams and leaders.</p><h3>Analytics Engineering</h3><p>Analytics Engineering is the practice of building clean and reusable data sets (models) for analysts, machine learning teams, and everyone else who interacts with our BI tools. At Mothership this is done by analytics engineers and data analysts. We’re enthusiastic about dbt and agree that analysts are the right people to design and build these models, as they are the ones who use them most extensively.</p><figure><img alt="A diagram in 4 sections: Data Sources, Ingestion, Modeling, General Access. Within the Modeling section are subsections labeled: Modules, Marts, Misc. &amp; Metrics. There is also a Testing and Validation subsection that overlaps both Modeling and Ingestion" src="https://cdn-images-1.medium.com/max/1024/0*CcJlx9QWs5VjM1ic.png" /><figcaption>How we organize our analytics data processes</figcaption></figure><p>As we operate an Extract Load and Transform model (ELT), rather than ETL, data arrives on the analytics database unmodified from the source system. This is then cleaned onto staging tables where it is formatted appropriately and presented as an ideal version of the production data. This is where the first set of basic validation tests live, usually generic field-level constraints.</p><p>Given the mission to generate trusted and extremely usable data models, Mothership’s data team cultivates distinct expertise on the domains we work in even before any analysis begins. The task of mapping production data to business processes (and testing all the assumptions in between!) is necessary for the responsible presentation of data. Providing a shared decision-making context requires models that are natural to the business stakeholders and legible to the engineering and product teams. Documentation and data stewardship are key processes of the data team.</p><h3>The Modular Approach</h3><p>Once data is staged and understood we build modularly toward wide tables that we call <em>marts.</em> These tend to align to key business entities, and are normalized as Kimball dictates. Where we deviate from Kimball and lean into the strengths of modern column store databases is by collecting very many dimensions and values onto the table. This takes advantage of the efficiency of a column store database and eliminates the expense and potential confusion of multiple or complex joins.</p><p>Rather than define marts in long queries with multiple derived/temporary tables (CTEs) we break these down into dbt models and construct the mart modularly. An example of this modular approach would be calculating the relevant accounting metrics per shipment onto their own table. Where Kimball might have us model all the facts relating to a shipment in the mart directly, by treating what would be a CTE(s) as their own dbt model, we can test this output of the dbt model against source data before passing it through to other models. This also encourages re-use the defined and documented values in other analysis or outputs.</p><figure><img alt="DAG screenshot from dbt showing three streams of dependency flowing into a model called ‘mart shipment’" src="https://cdn-images-1.medium.com/max/1024/0*nMRLkML91-SzDWNd.png" /><figcaption>A partial view of a DAG for one of our main marts showing 3 modular models of different complexities.</figcaption></figure><p>These modules tend to be domain specific, and in the case of complex business logics, rendered in distinct stages. Here we implement more complex secondary testing, including relational tests. This also gives us greater visibility into the runtime of elements of the mart.</p><p>Like most teams using a modern data stack we make use of version control, continuous integration, and typical software development practices. Tests are included as part of the release of new models and usually include not just completeness and matching against source and staging data but also tests against expected forecasts designed to alert us to issues the the extract and load steps.</p><p>This modularity allows us to partner with our Machine Learning Engineering team as creators and consumers. When they craft a query or deploy a model that generates data, those outputs can be added to the marts or combined with some other set of modules. Likewise, key values or segmentations used for training ML models can be added for common use. Another benefit here is that when a model graduates to a feature we simply sub in the source systems and transition to production visibility very quickly, having already built pipelines for data visualization or other analysis.</p><h3>Onward!</h3><p>For those of us working as analysts, especially at start-ups, migrating the ownership of engineering analytics models to people who will be using that data directly feels like a natural progression. While some would say this is just Kimball by another name, the consolidation of data ingestion and the opening up of transformation and modeling processes allows data teams to build sustainable resources in the act of discovery and analysis.</p><p>Many analytics teams measure themselves by a time to insight metric (or at least their stakeholders do) and in some orgs this has been at odds with the initiative to automate systems and follow better development practices. Analytics engineering aims to resolve that conflict by embedding automation and engineering into the process.</p><p>A good data modeling process empowers the business to make data driven decisions, enables curated self-service and ensures scalability, reliability, and shared context. Part of what makes tools in the <a href="https://blog.getdbt.com/future-of-the-modern-data-stack/">Modern Data Stack</a> so successful is that their value is obvious to users. Our goal is to make the value of the data team as obvious to our stakeholders as these tools are to us.</p><p><em>BW</em></p><p>In the future we’ll follow up with posts about our data ingestion processes, metrics modeling, and some alternatives to wide mart tables that we’ll be using for event data.</p><p>Learn more about Mothership and <a href="https://www.mothership.com/careers">join our team</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d061b66bec3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mothership/analytics-engineering-at-mothership-8d061b66bec3">Analytics Engineering at Mothership</a> was originally published in <a href="https://medium.com/mothership">Mothership</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>