<?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[Stories by Troy Mass on Medium]]></title>
        <description><![CDATA[Stories by Troy Mass on Medium]]></description>
        <link>https://medium.com/@troymass?source=rss-733a223826ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KNWuK6DTMVOyzppn5IO4jg.jpeg</url>
            <title>Stories by Troy Mass on Medium</title>
            <link>https://medium.com/@troymass?source=rss-733a223826ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:16:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@troymass/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scalable Job Scheduler at project44]]></title>
            <link>https://medium.com/project44-techblog/scalable-job-scheduler-dfc02420e8c4?source=rss-733a223826ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfc02420e8c4</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[supply-chain]]></category>
            <category><![CDATA[cron]]></category>
            <dc:creator><![CDATA[Troy Mass]]></dc:creator>
            <pubDate>Tue, 04 Apr 2023 15:02:09 GMT</pubDate>
            <atom:updated>2023-04-12T21:24:24.504Z</atom:updated>
            <content:encoded><![CDATA[<p>At project44, we use a lot of cron jobs. They are often used for polling 3rd party APIs to fetch data for shipments, recalculate things such as ETAs, or check to see if expected data never arrived. Previously, we used Quartz Framework but found that it struggled to scale.</p><p>Quartz is a great framework running arbitrary Cron or 1-time jobs because it guarantees that the execution starts on time and tracks execution failures. It relies on a few database tables to keep track of jobs and their state. The biggest issue for scaling is that it requires a lock on the table to acquire new jobs to run. This is especially problematic with a large number of jobs with relatively short execution times.</p><p>The jobs that project44 runs are less sensitive to execution failures since they are often polling jobs which, if they fail, will simply be re-triggered a few minutes later and pick up whatever they missed. Additionally, the timing is flexible; they need to run every N-minutes rather than at a specific minute of each hour.</p><h3>System Requirements</h3><ul><li>Able to trigger execution of a job every N minutes</li><li>Support for a variety of intervals (1, 2, 5, 10, 15 min, 1hr, 6hr, 24hr)</li><li>Eliminate job creation as a point of failure during synchronous flows</li><li>Able to smooth out bursts of jobs</li></ul><p><strong>Load Testing:</strong></p><p>In production, this service creates/updates/deletes 600+ jobs every minute and triggers well beyond 15k jobs per minute but it has been load tested well beyond these numbers. The values measured during load testing were:</p><p><em>CrUD operations: 10k / minute<br>Jobs triggered: 288k / minute<br>Load testing hardware: Postgres: 1 core, 6 GB RAM box. Service: 3 nodes<br>* note that the scheduler is triggering the jobs by sending Kafka messages, downstream services actually execute these jobs.</em></p><h3>System Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*En0PzgbReMdVNe5tbm5MTA.png" /></figure><ol><li>Systems create/update/delete jobs via Kafka. The job id, interval, and output topic are specified by the owning service. Any information that will be required to execute the job is stored within the job details.</li><li>CRUD operations are consumed and persisted. Jobs are assigned an offset within their interval and a random shard number.</li><li>Every half second, the job scheduler uses Quartz to triggers 1 of 120 shards to execute.</li><li>The scheduler queries the database for all jobs which need to be triggered during this minute (usually a few hundred per shard) and writes a message to the appropriate Kafka topic for each job.</li><li>The service which wanted the job consumes the Kafka topic and executes any code necessary for each job triggering message.</li><li>When the job is no longer needed, the owning service sends a delete command to Kafka</li></ol><h4>Job Object</h4><pre>{<br> &quot;id&quot;: &quot;&quot;, // String. Globally unique id for this job<br> &quot;startDateTime&quot;: &quot;&quot;, // Optional. Allows you to schedule a job to start in the future<br> &quot;executionInterval&quot;: &quot;EVERY_15_MINUTES&quot;, // Frequency of how often the job should trigger<br> &quot;topic&quot;: &quot;&quot; // Indicates which Kafka topic the message should be sent in order to trigger the job<br> &quot;jobDetails&quot;:{<br>  // Freeform data for triggering the job<br>  // Add whatever fields you need<br> }<br>}</pre><h3>Making it scale</h3><h4>Selecting jobs to trigger</h4><p>The secret to making this system scale is be not running any arbitrary Cron expression. Instead the system limits clients to a few select intervals. The example below shows 1, 5, 15, 60 minute, and 24 hr jobs but we support a few additional intervals. The scheduler runs a single Postgres query to find all jobs that need to be triggered. A few simple B-Tree indexes on the Postgres table do all of the heavy lifting to find jobs and the Postgres query planner handles doing BitMap AND and OR operations between these indexes.</p><h4>Sharding</h4><p>Sharding helps the service in 3 ways, it lets us run multiple scheduler nodes, it reduces the number of records returned from each SQL query, and it helps to smooth out job execution across each minute. A single Quartz job is used to triggering each shard. The jobs are staggered every 1/2 second to smooth out the load on the system (instead of large bursts once per minute). If additional scaling is needed, more shards can be created and spaced out at 1/3 second, 1/4 second, or even smaller increments.</p><h4>Reads vs Writes</h4><p>When triggering a job, a single read query can select hundreds of jobs which need to be triggered. By not keeping track of state or having any time columns such as nextTriggerTime, the service does not have to make any writes when the jobs are triggered. The only writes are when the job is created, updated (such as changing the interval), and deleted. In practice this means about 4% of the overall operations are writes while 96% are reads.</p><h3>Database Structure</h3><p>The database primarily uses a single table which stores all active jobs that need to be triggered. Jobs are hard-deleted when they end. Below shows an example of the query used by a scheduler firing for shard 65 at a time of 13:37:**. Note that the offset values have been calculated by taking the UTC epoch minute and doing a modulus by the desired interval. The color coded columns and query fragments indicate the indexes used to find those records. The 2 bolded records are the only jobs which should be returned by this query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6WgACBdfcPCFcJMRNgcaxg.png" /><figcaption>Example table structure, scheduler query, and indexes</figcaption></figure><p>Below you can see the results from SQL’s EXPLAIN showing how Postgres’ query planner utilized the indexes to find the desired records.</p><pre>Bitmap Heap Scan on job  (cost=951.29..2548.42 rows=423 width=210)<br>  Recheck Cond: ((shard = 1) AND (((interval_minutes = 1) AND (offset_minutes = 0)) OR ((interval_minutes = 5) AND (offset_minutes = 2)) OR ((interval_minutes = 15) AND (offset_minutes = 7)) OR ((interval_minutes = 60) AND (offset_minutes = 7)) OR ((interval_minutes = 1440) AND (offset_minutes = 1027))))<br>  Filter: (start_date_time &lt;= &#39;2021-12-31 00:00:00+00&#39;::timestamp with time zone)<br>  -&gt;  BitmapAnd  (cost=951.29..951.29 rows=428 width=0)<br>        -&gt;  Bitmap Index Scan on job2_shard_idx  (cost=0.00..155.59 rows=12689 width=0)<br>              Index Cond: (shard = 1)<br>        -&gt;  BitmapOr  (cost=795.34..795.34 rows=51667 width=0)<br>              -&gt;  Bitmap Index Scan on job2_interval_offset_idx  (cost=0.00..316.60 rows=20817 width=0)<br>                    Index Cond: ((interval_minutes = 1) AND (offset_minutes = 0))<br>              -&gt;  Bitmap Index Scan on job2_interval_offset_idx  (cost=0.00..76.87 rows=4844 width=0)<br>                    Index Cond: ((interval_minutes = 5) AND (offset_minutes = 2))<br>              -&gt;  Bitmap Index Scan on job2_interval_offset_idx  (cost=0.00..224.79 rows=14836 width=0)<br>                    Index Cond: ((interval_minutes = 15) AND (offset_minutes = 7))<br>              -&gt;  Bitmap Index Scan on job2_interval_offset_idx  (cost=0.00..171.67 rows=11124 width=0)<br>                    Index Cond: ((interval_minutes = 60) AND (offset_minutes = 7))<br>              -&gt;  Bitmap Index Scan on job2_interval_offset_idx  (cost=0.00..4.89 rows=46 width=0)<br>                    Index Cond: ((interval_minutes = 1440) AND (offset_minutes = 1027))</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfc02420e8c4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/project44-techblog/scalable-job-scheduler-dfc02420e8c4">Scalable Job Scheduler at project44</a> was originally published in <a href="https://medium.com/project44-techblog">project44 TechBlog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Architecture at project44]]></title>
            <link>https://medium.com/project44-techblog/system-architecture-at-project44-d79aabef50ed?source=rss-733a223826ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/d79aabef50ed</guid>
            <category><![CDATA[logistics]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Troy Mass]]></dc:creator>
            <pubDate>Mon, 04 Apr 2022 21:26:52 GMT</pubDate>
            <atom:updated>2022-04-04T21:26:52.361Z</atom:updated>
            <content:encoded><![CDATA[<p>Whether your shipments and orders are on the ground, on the high seas, or in the air, <a href="https://www.project44.com/">project44</a> tracks it using cloud technology. As a consumer, we are accustomed to knowing that our Amazon package is 3 stops away, but that level of visibility is unheard of for warehouse managers, retailers, and other supply chain workers who have to make phone calls to know when their truck, train, ocean ship, or air shipment will arrive. project44 provides this level of visibility to retailers which allows them to know when additional items will be in stock. Our Last Mile products enable large retailers to provide this visibility to end consumers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*V6kE6fqHmaDmoAEhOA9DQg.png" /><figcaption>Vehicle positions. Color and height represent density of updates in that tile.</figcaption></figure><h4><strong>System Functional Requirements</strong></h4><ul><li>Allow shippers to get rate quotes and to dispatch shipments from their carriers</li><li>Associate orders and items to the shipments and vehicles which are transporting them</li><li>Provide the planned and actual times for key milestones that a shipment goes through (pickup, transfers, clearing customs, out for delivery, delivery, etc)</li><li>Use data science to provide estimates for future milestones (estimated time of arrival, delivery, etc)</li><li>Provide visibility and communication tools for shipment receivers</li><li>Enable yard managers to manage and schedules docks for incoming/outgoing vehicles</li></ul><h4><strong>Scalability Requirements</strong></h4><ul><li>Each shipper may work a network of hundreds to thousands of carriers</li><li>The project44 system connects to 130,000+ carriers in 170 countries</li><li>Over 1 billion shipments tracked per year</li></ul><h3>Technologies Used</h3><ul><li>Google Compute Engine, Kubernetes, Spinnaker</li><li>Postgres, Elasticsearch, MongoDB</li><li>Java, Spring, Python, React, Typescript</li><li>Kafka</li></ul><h3><strong>System Design</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*waOKg0ae8m6lRPZ-6tZxgA.png" /></figure><h4>User Interfaces</h4><p>We provide different user interfaces for a variety of needs and user personas. Our Last Mile visibility is used by end consumers to view tracking details and request support from our enterprise shippers and retailers. The Visibility Operations Center provides end to end shipment and order visibility for first mile and middle mile allowing users to track shipments, view the health and planned vs actual items of orders, and break down their network by locations. The Network Management Center allows shippers to configure the carriers that they work with. Yard Management Center allows location managers to schedule the loading docks at their locations. All of these systems are built-upon and manage the core project44 system.</p><h4>API Layer</h4><p>The project44 API enables customers to integrate their systems directly or to use one of our provided adapters for their off-the-shelf Transportation Management System. Integrated systems are able to fetch rate quotes, dispatch shipments, get tracking data, and view scanned documents. It can also push data updates to webhooks on their system in order to provide data in near real time.</p><h4>Tracking Visibility</h4><p>The system contains business logic which is unique to sourcing, linking, and processing data for different modes of transportation (parcel, partial trucks, full trucks, rail, ocean, and air). Our ETA data science models account for the nuances of each mode to compute the ETA within that mode and to provide end-to-end ETA for intermodal shipments. The unified tracking system links together data from all modes and normalizes the modal data to a single, intermodal view. The collaborative visibility system allows shippers to share their shipments to the recipients and allows viewing shipment data in different parts of the world.</p><h4>Rating, Dispatch, Digital Documents</h4><p>These systems manage all parts of the life cycle of a shipment before and after it is moving. Users can gather rate quotes from their entire network of carriers, then dispatch a shipment to the carrier and schedule the pickup. It also provides digital documents for scanned bills of lading, delivery receipts, and more.</p><h4>Ingestion Pipeline</h4><p>project44 sources data from tens of thousands of different sources. Some of these sources require us to poll while others can push it to us upon request or push all data. This data is ingested, transformed, and then sent to the core tracking systems for processing using Kafka. It can source data from older, fixed-field-width Electronic Data Interchange (EDI) systems as well as vehicle position data for aircraft, ships (AIS), rail cars, and trucks. We also have connections to thousands of different carrier APIs to poll and many times more carriers that have integrated to the p44 API to push data into the system for key milestone events.</p><p>The ingestion pipeline also enables carriers to control with-whom and where their data is shared using relationships mapped out by the carrier network directory. Carriers can opt to keep their data regionally locked and can manage which shippers they work with to grant access to vehicle data only for the time that the shipper had goods on the vehicle.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d79aabef50ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/project44-techblog/system-architecture-at-project44-d79aabef50ed">System Architecture at project44</a> was originally published in <a href="https://medium.com/project44-techblog">project44 TechBlog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My first Chicago Mackinaw Race]]></title>
            <link>https://medium.com/@troymass/my-first-chicago-mackinaw-race-1af123b995cb?source=rss-733a223826ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/1af123b995cb</guid>
            <category><![CDATA[sailing]]></category>
            <category><![CDATA[racing]]></category>
            <dc:creator><![CDATA[Troy Mass]]></dc:creator>
            <pubDate>Thu, 03 Aug 2017 06:17:56 GMT</pubDate>
            <atom:updated>2017-08-03T06:17:56.551Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<p>289 nautical miles, 4 days, 7 people. The longest race I’ve done. Well… almost done. 2017 was my first time racing in the Chicago Yacht Club Race to Mackinaw Island and Lake Michigan gave us everything it had to muster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QO3P69-0q6VcPwSGw1R00Q.jpeg" /></figure><p>The race started out pretty well. Downwind for about 13 hours from 11am until midnight. We were holding with the fleet, albeit a little behind. We were gambling on a wind shift that never came.</p><p>Around midnight was when things started to change. I was off duty from 9p until 12a and caught what sleep I could up in the bow of the boat. Let me just say, the sounds of the boat rushing through the water were terrific! A bit before midnight I was woken up by the other guys changing sails. They dropped the spinnaker (downwind sail) and unfurled the jib.</p><p>Winds had shifted from SE to N as the cold front passed overhead. As I came onto shift, things started to get wonky in the wake of the front. We didn’t get any rain, but we got some very weird wind conditions. A few times we changed our minds with what sails we should be carrying. Furling the jib at one point, partially at another. As we went to unfurl it to go full jib, the entire boat shook and the sails flapped violently as the wind went every which way. I didn’t see the wind instruments as I was too busy with the “oh s***, roll it back up!!!!”</p><p>We suspect we were hit by a downburst on the back side of the front. We were hit a few other times and saw winds in to the 40 knots. They were brief, but strong.</p><p>At one point when the wind picked up, we had partially dropped the main and reefed it. At that time we noticed an issue with the cabin-top winch used for the main halyard. A little while later, winds started to go very soft so we decided to go back to full main. Since we were down a winch, we led the line to another and used it. But in the dark and semi-chaotic state, we managed to completely foul the line in the winch with multiple wraps under the auto-tailer (there should never be any line under there at all), and a few overrides on the winch drum.</p><p>There was a bit of yelling at this point about how bad this was. The halyard was all the way up and tight at this point, so there was no real good way to undo the screw-up. We knew that if any sort of high winds or storm were to hit us right then, we’d be taking a knife to that line and crippling us from the race.</p><p>I took over the helm as one of the off duty crew and the captain got out the tools in search of some way to fix it that didn’t involve cutting the brand new, very expensive line.</p><p>Oddly enough, this was my most enjoyable part of the race. For a short while we had beautiful winds, waves from the stern, and the boat just sang as she surfed through the water. I was at at the helm, 1 crew trimming sails for me, and 2 others and the captain trying to free our fouled winch.</p><p>Over the radio around this time we heard 2 distress calls. The first was a man overboard. We only heard bits and pieces of the call. But were able to hear the location and determined that we were many miles away, and several other closer boats were offering assistance.</p><p>The second was a capsized trimaran. Again far from us and other boats nearby were lending aid. So we continued the race.</p><p>I was still at the helm when the winds started to go wacky again. The pressure died and the primary thing pushing the boat forward were the waves and our own momentum. Up until this point I had primarily been driving based on my wind angle instruments. As the wind died and the apparent angle shifted forward I attempted to follow the angle until a few seconds later I glanced over at my compass and realized I was practically pointed south. I was supposed to be going north. Oops.</p><p>The wind had died so much that the jib was basically useless and was flapping around. We furled it and I navigated the boat back onto the correct course and the winds picked up a few minutes later.</p><p>Eventually, the very patient off duty crew member who had been meticulously picking at the ball of horribleness wrapped around our primary winch was able to free the knot saving the halyard and our winch. A quick disassembly and reassembly of the cabin-top winch also solved the issue found in the first place. We were back in business!</p><p>Eventually I was relieved from the helm and we continued into the ever increasing wind. But soon the wave direction began to change as the wind turned the waves around and we began beating against them. And winds were getting stronger.</p><p>By this point, we had reefed the main again, but the shape was terrible and we were struggling to make any useful angle to the wind. The crew down below were asked to sleep as far to the high side of the boat as possible to help our heel angle. By now, our shift schedule was pretty much out the window as people found it difficult to find sleep down below and decided to just find something to do on deck instead.</p><p>We continued this for several more hours, ad-hoc switching duty and getting what little sleep we could until daybreak.</p><p>By daybreak we were approaching the Michigan shore. The wind had continued to get stronger through the night, blowing into the 20s and waves had developed to be 8–10 feet. Most of us were sleep deprived, cold, and dehydrated. As we were waking up down below we found ourselves quickly sea sick and had to get up on deck as quickly as possible where fresh air and a line-of-sight to the horizon would help.</p><p>Two of our crew were sick enough to have a pass-the-bucket going around. One of which progressed to the point he was using the bucket every 20–30 minutes.</p><p>Hours of waves crashing over the boat meant that my light-duty foul weather jacket had soaked through and was no longer keeping me warm and I was shivering pretty bad. One of these waves sent so much water over the top of the boat that it floated me and the guy next to me off our seats and pushed us down into the cockpit.</p><p>I eventually put on an extra waterproof windbreaker underneath the foul weather coat which helped. My biggest takeaway from this adventure: don’t be too cheap to buy good foul weather gear! Sitting on the edge of that boat shivering I would have paid hundreds of dollars on the spot to have been warm.</p><p>By 8 or 9am we began to consider dropping out of the race. Based on forecasts, we knew that it would be 12–18 more hours of this brutal beating and we knew were weren’t making much ground. And then the wind would basically die completely, leaving us bobbing like a duck on the washing machine of waves created by the winds.</p><p>The captain put it to a vote: continue racing or bag it. The crew voted 3 to 3 leaving the tie breaker to the captain. He decided to go in. It took a little while searching charts and making phone calls before we were able to find a harbor. The nearest harbor was too shallow for us to enter in the wave conditions we had and the next closest took several hours to reach.</p><p>We hugged the Michigan shoreline, feeling slightly protected by Little Sable Point, and then Big Sable Point. Eventually reaching Ludington Harbor.</p><p>As we entered the harbor, we were relieved to find a dozen boats who had retired from the race in the same harbor including a handful of the boats in our own division. At least we weren’t alone.</p><p>By the time we had moored the sun had come and we were beginning to dry and feel warm. Our first half an hour ashore did not feel like we were on stationary land due to our sea legs.</p><p>We ate at a delicious restaurant for dinner, basically our first meal of the day since most of us weren’t feeling too well on the boat. At the start of the race we made jokes about our rations of sandwiches and how if this race went long, we might run low on sandwich rations. We were each allotted 2 sandwiches a day for 3 days. If the race took 4 we were going to be eating literal peanuts!</p><p>So 7 people x 2 sandwiches a day x 3 days = 42 sandwiches. Want to know how many total sandwiches were eaten during the race?</p><p>Zero. Zilch. Nada. Not a single sandwich was eaten.</p><p>We each made our plans on how to get home. For myself and 2 others, we hitched a ride with another crew to the Michigan and Indiana border where we stayed and then took the south shore trains back into the city the next day.</p><p>Checking the online race tracker we watched as nearly a third of the boats retired from the race. 301 boats started, 97 retired.</p><p>The man overboard in the water went over as he came onto his duty shift. He came onto deck just as the boat hit a wave sending him straight through the lifelines and into the water. Fortunately he was wearing a lifejacket. Unfortunately his emergency light failed, however he also had a whistle. He used the whistle to be located by his own boat. They would drive for a little bit, shut the engine off, listen for the whistle, then drive towards it. He was in the water for an hour before being rescued.</p><p>And the capsized trimeran had 4 crew on it. All of them were on deck at the time and stayed with the boat. They were rescued safely by the coast guard.</p><p>Overall my first Chicago Mac was far less than perfect, but I plan to do it again next year! Buy the right gear, sail the whole race, win, party on the island afterwards. Looking forward to it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1af123b995cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>