<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Peter Goldsborough</title>
    <description>Musings on navigating the tech bubble with philosophy and self-improvement.</description>
    <link>http://www.goldsborough.me/</link>
    <atom:link href="http://www.goldsborough.me/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>Non-Blocking Parallelism for Services in Go</title>
        <description>&lt;p&gt;Go has plenty of useful builtin functionality for safe, concurrent and parallel code. However neat those features may be, they cannot write your program for you. As is the case for many languagges, the most important morsels of knowledge are not in the features of the language, but in the well-known &lt;em&gt;patterns&lt;/em&gt; that compose those features into solutions that can address frequently reoccurring problems. I’m relatively new to using Go as my daily bread-and-butter language and recently encountered a useful pattern that I thought worth sharing. I’m told that at Palantir it is called the &lt;em&gt;tickler&lt;/em&gt; pattern.&lt;/p&gt;

&lt;h2 id=&quot;the-tickler-pattern&quot;&gt;The Tickler Pattern&lt;/h2&gt;

&lt;p&gt;The tickler pattern addresses a very particular scenario:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;You have a service processing requests of some kind and looping forever,&lt;/li&gt;
  &lt;li&gt;Calling the service should not block the caller,&lt;/li&gt;
  &lt;li&gt;You optionally want to bound the amount of parallelism in the service, i.e. how many requests are processed at a time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The crux of the pattern will look as follows:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list.List&lt;/code&gt; will represent the service’s internal queue,&lt;/li&gt;
  &lt;li&gt;We’ll have the service loop forever, waiting for a signal to reconsider the contents of the queue,&lt;/li&gt;
  &lt;li&gt;When a new request is enqueued, this signal is sent,&lt;/li&gt;
  &lt;li&gt;When the service completes the work for a request, this signal is also sent,&lt;/li&gt;
  &lt;li&gt;A semaphore puts a limit on the number of in-flight requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s look at the code and discuss these steps in more detail. We begin with our types:&lt;/p&gt;

&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;// Dummy request -- usually some Protobuf/Thrift struct&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;sync&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Mutex&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;queue&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sema&lt;/span&gt;       &lt;span class=&quot;k&quot;&gt;chan&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;loopSignal&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;chan&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We’ll use a channel to represent a bounded semaphore. This is perfectly idiomatic in Go, although you could also use &lt;a href=&quot;https://godoc.org/golang.org/x/sync/semaphore&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sync.Semaphore&lt;/code&gt;&lt;/a&gt; for this if you really wanted to. One of our explicit requirements for the kind of solution we wanted was that the caller shall never block when making a request. This requirement is met by the fact that we will always first enqueue a request, leaving its processing to be done asynchronously. Note that my solution will not provide a way to retrieve a response for the request.&lt;/p&gt;

&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EnqueueRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Lock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;defer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Unlock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PushBack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Added request to queue with length %d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tickleLoop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;nil&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We acquire a mutex for our queue since we will have multiple goroutines accessing it concurrently. We enqueue the request and then notify the loop. The last part is explained in a bit. Now that we have a way of adding requests, we can work on the code to handle the requests. Since this is a service, we’ll have it loop forever waiting for new work to be done. This is also where the loop signal comes into play:&lt;/p&gt;

&lt;div class=&quot;language-golang highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Starting service loop&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loopSignal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tryDequeue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Done&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Loop context cancelled&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;loop&lt;/code&gt; method will have the service loop until the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Done()&lt;/code&gt; channel on a context that we pass in is fulfilled. This will allow us to shut down the service gracefully at the end of our program, or in case an error occurs. More importantly, we wait for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;loopSignal&lt;/code&gt; to tell us to &lt;em&gt;reconsider the queue&lt;/em&gt;. This signal is sent on one of two occasions:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;When a new request is enqueued,&lt;/li&gt;
  &lt;li&gt;When we finish processing a request.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can convince yourself that these are the only two events in the lifetime of our service at which it is necessary to consider the queue. If the service’s queue is empty, enqueuing a new request tells the service to look at this new request. If a request is enqueued but it cannot be handled right away because we’ve reached the limit on the parallelism we configured, the only time this will change is when a request completes processing, i.e. when the semaphore is replenished by one token.&lt;/p&gt;

&lt;p&gt;Let’s now look at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tryDequeue&lt;/code&gt;, which is called whenever the loop is “tickled”. Its unconfident naming stems from the fact that when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tryDequeue&lt;/code&gt; is called, we:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Don’t know whether the queue has any requests at all, since the signal could have originated from having finished processing the last in-flight request,&lt;/li&gt;
  &lt;li&gt;Don’t know whether we have sufficient resources if there is a request in the queue.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tryDequeue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Lock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;defer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Unlock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sema&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dequeue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Dequeued request %v&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;go&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Received loop signal, but request limit is reached&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dequeue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;element&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We check for the first case of uncertainty by testing the length of the queue. If we know we have work to do, we need to check if the semaphore has sufficient slots to allow for the request to be handled. Because our semaphore &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sema&lt;/code&gt; will be a buffered channel, we know that if the semaphore has no slots left, sending it a new token (the integer &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;) will block, or in this case trigger the default case. If we’ve reached our limit on parallelism, we simply punt on handling this request until the loop is tickled anew. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dequeue&lt;/code&gt; function is a little helper that takes care of the nasty business of popping an element from the queue, which is made to involve type casting because of Go’s lack of generics.&lt;/p&gt;

&lt;p&gt;If a request passes the demanding tests of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tryDequeue&lt;/code&gt; function and is elected for processing, we take care of it in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; method:&lt;/p&gt;

&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;defer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;replenish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Processing request %v&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;// Simulate work&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;After&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Duration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rand&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Intn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Millisecond&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replenish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sema&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Replenishing semaphore, now %d/%d slots in use&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sema&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;cap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sema&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tickleLoop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;What’s really more interesting is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;replenish&lt;/code&gt; function. This function has two responsibilities. First, it frees a slot in the semaphore so that a new request may be handled. Second, it tickles the loop to inform it that it’s a good time to consider the request queue again, in case there are requests that were blocked on other requests completing first. If you recall, this is the second of two cases in which the request queue must be reconsidered.&lt;/p&gt;

&lt;p&gt;Let’s also lift the veil of mystery on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tickleLoop&lt;/code&gt; function. It simply makes a non-blocking send to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;loopSignal&lt;/code&gt; channel:&lt;/p&gt;

&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tickleLoop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loopSignal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{}{}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, we tie everything together in the constructor of our service:&lt;/p&gt;

&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NewService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requestLimit&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;service&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;      &lt;span class=&quot;n&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;New&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;sema&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;       &lt;span class=&quot;nb&quot;&gt;make&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;chan&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requestLimit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;loopSignal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;make&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;chan&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{},&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;go&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;service&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We construct &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;loopSignal&lt;/code&gt; as a buffered channel with one free slot. If the service’s loop is currently waiting for a value from the channel, a single send will tell it to reconsider the queue. If it is currently considering the queue but a request completes processing, we need to “enqueue” a signal so that when it exits &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tryDequeue&lt;/code&gt; and re-enters the context of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;select&lt;/code&gt; statement, it knows to immediately reconsider the queue. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sema&lt;/code&gt; semaphore is a channel with sufficient buffering for the number of concurrent processing slots we wish to allow for the service. My &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NewService&lt;/code&gt; constructor starts the loop right away, but you could also make &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Loop&lt;/code&gt; a public method and do this outside of the constructor.&lt;/p&gt;

&lt;h2 id=&quot;demo&quot;&gt;Demo&lt;/h2&gt;

&lt;p&gt;A brief demonstration of our service in action is due:&lt;/p&gt;

&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cancel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WithCancel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Background&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;defer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cancel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;service&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NewService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EnqueueRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Fatalf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;error sending request: %v&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;After&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Duration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rand&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Intn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Millisecond&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Second&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We create a cancellable context for the service that we use to signal the service to terminate its loop. For this demonstration, I bound the parallelism to three requests. The infinite loop at the end simulates running the service forever. Running this code produces the following output (out of many possible variations):&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Starting service loop
2020/12/06 12:09:43 Dequeued request 0
2020/12/06 12:09:43 Processing request 0
2020/12/06 12:09:43 Replenishing semaphore, now 0/3 slots in use
2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Dequeued request 1
2020/12/06 12:09:43 Processing request 1
2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Dequeued request 2
2020/12/06 12:09:43 Processing request 2
2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Dequeued request 3
2020/12/06 12:09:43 Processing request 3
2020/12/06 12:09:43 Replenishing semaphore, now 2/3 slots in use
2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Dequeued request 4
2020/12/06 12:09:43 Processing request 4
2020/12/06 12:09:43 Replenishing semaphore, now 2/3 slots in use
2020/12/06 12:09:43 Replenishing semaphore, now 1/3 slots in use
2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Dequeued request 5
2020/12/06 12:09:43 Processing request 5
2020/12/06 12:09:43 Replenishing semaphore, now 1/3 slots in use
2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Dequeued request 6
2020/12/06 12:09:43 Processing request 6
2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Dequeued request 7
2020/12/06 12:09:43 Processing request 7
2020/12/06 12:09:43 Replenishing semaphore, now 2/3 slots in use
2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Dequeued request 8
2020/12/06 12:09:43 Processing request 8
2020/12/06 12:09:43 Replenishing semaphore, now 2/3 slots in use
2020/12/06 12:09:43 Added request to queue with length 1
2020/12/06 12:09:43 Dequeued request 9
2020/12/06 12:09:43 Processing request 9
2020/12/06 12:09:44 Replenishing semaphore, now 2/3 slots in use
2020/12/06 12:09:44 Replenishing semaphore, now 1/3 slots in use
2020/12/06 12:09:44 Replenishing semaphore, now 0/3 slots in use
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can observe the dance between requests being enqueued and the semaphore being replenished as requests complete. If we increase the rate at which requests are being sent by reducing the delay between calls to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;service.EnqueueRequest&lt;/code&gt;, we see that the queue grows quite a bit before the semaphore is replenished by a completing request:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2020/12/06 12:17:58 Added request to queue with length 1
2020/12/06 12:17:58 Starting service loop
2020/12/06 12:17:58 Dequeued request 0
2020/12/06 12:17:58 Processing request 0
2020/12/06 12:17:58 Added request to queue with length 1
2020/12/06 12:17:58 Dequeued request 1
2020/12/06 12:17:58 Processing request 1
2020/12/06 12:17:58 Added request to queue with length 1
2020/12/06 12:17:58 Dequeued request 2
2020/12/06 12:17:58 Processing request 2
2020/12/06 12:17:58 Added request to queue with length 1
2020/12/06 12:17:58 Received loop signal, but request limit is reached
2020/12/06 12:17:58 Added request to queue with length 2
2020/12/06 12:17:58 Added request to queue with length 3
2020/12/06 12:17:58 Received loop signal, but request limit is reached
2020/12/06 12:17:58 Received loop signal, but request limit is reached
2020/12/06 12:17:58 Added request to queue with length 4
2020/12/06 12:17:58 Received loop signal, but request limit is reached
2020/12/06 12:17:58 Added request to queue with length 5
2020/12/06 12:17:58 Received loop signal, but request limit is reached
2020/12/06 12:17:58 Replenishing semaphore, now 2/3 slots in use
2020/12/06 12:17:58 Dequeued request 3
2020/12/06 12:17:58 Processing request 3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;And there we are – the tickler pattern! Not the only pattern for bounded parallelism in Go, but one that addresses the constraints we set out in the beginning very well. The only scalability flaw I see with it right away is that the service could run out of memory if the rate of new requests is much greater than the rate at which requests are processed, which could grow the queue to significant lengths. This could be addressed by rejecting requests out right if the queue has reached a certain length, or rate limiting clients whose volume and frequency of requests is too demannding. If you can think of other flaws, let me know!&lt;/p&gt;
</description>
        <pubDate>Sun, 06 Dec 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/go/2020/12/06/12-24-24-non-blocking_parallelism_for_services_in_go/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/go/2020/12/06/12-24-24-non-blocking_parallelism_for_services_in_go/</guid>
      </item>
    
      <item>
        <title>Why We Should Encourage Cheating On Exams</title>
        <description>&lt;p&gt;Cheating is a subjective concept. When a student “cheats” on an exam by stealthily pulling out their phone under their desk and looking up some information to solve a problem, we only call that “cheating” if somebody made up a rule beforehand that forbids it. These rules are not physical laws set in stone by nature. They are entirely artificial. If the examinator changes the rules to make looking up information on your phone during the exam perfectly legal, it is suddenly no longer cheating. If we can settle on this, we should immediately ask: why are the current rules in place and are they really the most &lt;em&gt;optimal&lt;/em&gt; rules?&lt;/p&gt;

&lt;p&gt;When we ask whether the rules that define cheating on an exam, a competition or an interview are &lt;em&gt;optimal&lt;/em&gt;, we need to talk about what the end of that exam is in the first place. In the tech industry, where interviews are our “exams”, we talk about extracting &lt;em&gt;signal&lt;/em&gt; or getting a certain &lt;em&gt;read&lt;/em&gt; from interview candidates. If a particular interview technique allows us to extract a lot of signal on a certain skill, like coding or system design, or a certain quality, like ability to teamwork or manage people, that means it tells us with sufficient precision that the candidate meets our bar in that category.&lt;/p&gt;

&lt;p&gt;For example, the signal a math teacher would like to extract – or should be extracting – from a math final is whether his pupils have intrinsically understood the concepts presented in class since the last exam and could apply them to some useful real world task (assuming the purpose of education is to be useful in life, which may be overly idealistic on my part). Instead, the typical rules educators define around academic dishonesty steer the signal into a totally different direction, usually towards providing an excellent read on how well students can stuff three months worth of content into their short-term memory through rote memorization.&lt;/p&gt;

&lt;p&gt;That said, not all rules are bad. Some are necessary to provide the right signal. For example, the signal the olympic committee wants to extract from a 100m track-and-field competition is to determine who is the fastest runner, by virtue of their athleticism and training. Since doping would augment the ability of an athlete beyond their natural athletic ability and the olympic committee is not looking for signal on which pharma company can produce the best doping drug, doping is not allowed. This rule perfectly supports the signal the committee is looking for.&lt;/p&gt;

&lt;p&gt;We see that the inherent purpose of rules in an exam is to steer the exam towards delivering a particular signal. We define the signal we want to get from the test and we define the rules that will best provide it. Given this, let’s take a look at two domains of testing that I’m particularly familiar with – tech interviews and school exams – and reason about whether we should call “cheating” a felony in these circumstances, or encourage more of it.&lt;/p&gt;

&lt;h2 id=&quot;tech-interviews&quot;&gt;Tech Interviews&lt;/h2&gt;

&lt;p&gt;I’ve been conducting technical interviews for software engineering candidates for a while now and it has really highlighted to me the criticality of finding the right signals from an interview. Interestingly, the tech industry is quite flexible in terms of interview methodologies. Different companies have come up with different interview practices, all aimed at determining which engineers will be successful contributors to the company and worth the financial, time and human (coaching) investment of hiring them.&lt;/p&gt;

&lt;p&gt;The most common form of interview for software engineering candidates is a “coding interview”, in which the candidate is asked to write code to solve a programming problem. These interviews are notorious for requiring textbook knowledge that is rarely used in an engineer’s day-to-day job. They’re a bit like asking a cook during an interview to apply knowledge from organic chemistry to produce a new dish, when they usually just use ready-made ingredients to do their job. Really everybody knows that these coding interviews are inaccurate proxies of whether somebody is a useful engineer, but they’re still very common, for a few reasons. For one, there’s an assumption that somebody who is generally intelligent and able to solve these riddles will also be smart enough to solve day-to-day engineering challenges. Another reason is that once in a blue moon you really do need to go down to the organic chemistry level to solve a problem and you’d rather have somebody on your team who can do that.&lt;/p&gt;

&lt;p&gt;The rules of coding interviews are relatively strict. We allow candidates the equivalent of looking words up in a dictionary, but we generally expect them to solve the problem from the ground up. Googling for a solution to the problem outright during an interview would be considered cheating, as would be asking their roommate for help. What’s funny about this is that what we consider “cheating” according to the rules we’ve set up for our interviews, is actually what engineers do all the time at their work. If a problem pops up at my job that requires some arcane textbook knowledge I can’t remember, I look it up online. When I can’t solve a difficult problem on my own, I ask my teammates if they have any good ideas or know of some existing approaches. It’s called resourcefulness and it’s called teamwork. In fact, somebody who doesn’t know how to effectively research problems on the internet or is socially incapable or too arrogant to ask teammates for help, and tries to solve every problem alone from the ground up, is not going to be an effective engineer. In the end, we get paid to solve problems efficiently, not to prove to ourselves that we’re smart.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Never memorize something that you can look up. – Albert Einstein&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the rules of the game lead to behavior that we actually want to see being classified as “cheating”, doesn’t that mean that the rules are bogus and not helping us get the signal we want? Yes. Yes, indeed. What’s good about the tech industry is that these flaws in the standard interview process are generally acknowledged. Because of this, companies are trying other approaches, such as “take home” problems. These are usually done autonomously, i.e. without an interviewer on the other side. The candidate just submits their solution when they’re done. They take a couple hours to solve and you can use the internet, your favorite tools, textbooks etc. If the format were altered to include teamwork with an employee or another candidate, you could even allow them to ask another person for help. Take home problems are an active step in the right direction of extracting the optimal signal in the optimal way during tech interviews.&lt;/p&gt;

&lt;h2 id=&quot;school-exams&quot;&gt;School Exams&lt;/h2&gt;

&lt;p&gt;While the tech industry acknowledges the flaws of the “standard approach” to interviewing and is actively experimenting with alternative approaches, our education system’s approach to examination is pretty much universally identical, universally stagnant and universally unquestioned. Ever since the dawn of mass market education the typical format of an exam has placed a strong emphasis on the idea that one’s memory is the only source of knowledge one should ever use or will ever have available to solve a problem. In most exams, all other resources such as textbooks, other human beings or – god forbid – the internet, are strictly forbidden by the rules of the game. Tapping knowledge from anywhere other than one’s brain is an act of cheating.&lt;/p&gt;

&lt;p&gt;Using the compass we’ve utilized so far in this article to determine whether rules are bogus, we can ask what sort of signal an exam with these rules lets us extract from pupils. I would argue that for most exams, the performance of students gives you a read on &lt;em&gt;how well those students have prepared for the exam&lt;/em&gt;. For the content of most exams, like vocabulary in a foreign language class, natural processes in a biology, physics or chemistry class or historical events in a history class, this means rote memorization. The exam gives us signal on how well the students have memorized the content they knew was due for the exam. For other exams, like a lot of math classes, we get great signal on how much the students have practiced the content. Very often, this means practicing processes at a mechanical level, to the point where they can be applied to new instances of a problem highly effectively. For example, exams will test how well students can take derivatives of functions. You cannot memorize all derivatives of all functions, but you can practice the mechanical process of taking a derivative for hours on end until you can take derivatives of almost any function, which is what the exam will test. Very rarely do exams test for an intrinsic understanding of the content.&lt;/p&gt;

&lt;p&gt;I repeat: &lt;em&gt;most school exams give an indication of how well students have prepared for the exam&lt;/em&gt;. If we were to ponder for just a moment about what an exam should actually test for – probably whether students have internalized the knowledge, comprehended why it is important to know this and most importantly whether they would be ready to utilize this knowledge in a real world setting – we would be likely conclude that the last thing we’d want our exam to test for, is whether the students acquired this knowledge exclusively for the exam. We’d probably want to prevent our exam from being &lt;em&gt;gamed&lt;/em&gt;. Unfortunately, it appears to me that very few educators realize the irony of their examination practices in this respect.&lt;/p&gt;

&lt;p&gt;There is one more signal our education system tries to extract from the way it tests its students, which is how one student compares to another. Our education system is obsessed with measuring people, obsessed with statisticizing human beings and bucketing them into narrow castes called A, B, C, D and F. The fundamental purpose of an education system should be to give you knowledge, grow your understanding of the world and foster your talents. In no way does a GPA score contribute to this goal in any way, shape or form. It’s sole purpose is to compare, so that some decision maker can compare you to somebody else, or compare your school district to another, or American kids to Chinese kids.&lt;/p&gt;

&lt;p&gt;Now that we’ve established that the real signal educators get from an exam is how well pupils have prepared for it and how the pupils compare to kids in Finland, the rules in place for most exams make a lot more sense. If we allowed students during an exam to look up stuff on the internet, then how could we really test that they put in any effort to prepare specifically for this exam? If we let students brainstorm a solution to an exam question with their classmates, then how could we put a number on Peter and a number on Paul and compare them to each other? More importantly, how could we do this for all 250 students taking the exam? What an inefficient way to test students that would be. The education factory would grind straight to a halt. It’s much, much easier to call this behavior cheating and keep mass producing graduates quantified and measured according to standardized criteria.&lt;/p&gt;

&lt;p&gt;So let’s assume that what we call cheating is henceforth allowed. Every exam in school will be open book and teamwork is allowed. Does that mean that the most resourceful student or the best communicator will succeed the most at the exam? No, because the person who rote memorizes all the content and mechanical processes required for the exam will still be faster, potentially completing more of the questions. Will that person fare better one month later when that knowledge needs to be utilized in a real world setting? Probably not, but he’ll do a lot better at the exam, because he’s better at gaming it, better at preparing for it – better at providing the signal that the exam is built to extract. This leads us to the same conclusion many kids make, albeit with a slightly more complex derivation: &lt;em&gt;exams are stupid&lt;/em&gt;. When it comes to being the optimal vehicle to educate people, they really are. They don’t teach students to be resourceful and learn how and where to look up information effectively to solve a problem. They don’t teach students the value of teamwork or the compounding effect multiple minds have when brainstorming a problem. Yet these are precisely the skills the knowledge worker of the 21st century needs.&lt;/p&gt;

&lt;p&gt;Exams should perish. We know that people learn by example, not by exam. In place of exams, test students’ knowledge in the real world, on real problems. All exams can and should be replaced by project work. Further, instead of teaching students how to game exams, teach them the tools they will need to succeed in the real world. Teach them how to Google something they don’t know. Teach them how to post a question in a help forum. Teach them how to program and solve data science problems instead of memorizing the times table. Teach them how to brainstorm together, how to hear out another person’s ideas without interrupting them. Teach them how to communicate a question clearly to another person without wasting their time so they can help you swiftly. Teach them how to synthesize information from many sources instead of memorizing information. I’d hire one student who was taught these skills over ten students who aced their exams, because I don’t need a coworker who can prepare for an exam, I need a coworker who can be resourceful and collaborative in solving problems. If that’s who we call a cheat, then I’m a cheat and I want a team of the worst cheaters out there.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;So what do I mean with “We Should Encourage Cheating on Exams”? My point is that if what we call “cheating on an exam” is actually behavior we want to encourage, then logically we should encourage more cheating. But that’s not actually the right solution. The right solution is not to cheat more, but to alter the rules of the exam so that this behavior is rewarded rather than reprimanded. The rules in place for exams are never set in stone, they are not axioms. They were put in place by somebody, thus they can be changed by somebody else. Ultimately, we decide the rules and the rules we decide on determine the signal we extract from an exam. Whatever test we are setting up, be it an interview or a school exam, we should start from the ground up by asking what signal we want to extract and then construct the minimal set of rules that will give us this signal in the most optimal way. It’s that easy. It’s that hard.&lt;/p&gt;
</description>
        <pubDate>Sat, 21 Nov 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/education/thoughts/2020/11/21/23-55-01-why_we_should_encourage_cheating_on_exams/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/education/thoughts/2020/11/21/23-55-01-why_we_should_encourage_cheating_on_exams/</guid>
      </item>
    
      <item>
        <title>Finding Joy Or Meaning In Your Work</title>
        <description>&lt;p&gt;I’m often told that I can consider myself lucky that I enjoy the work I do for a living. While I admit that I take this for granted, I equally appreciate that for many, many people work is just that: work. A necessity of life that pays the bills and enables the activities, hobbies and dreams that actually bring you joy. One reason I’ve taken my situation for granted is that for most of my professional career I’ve been surrounded by highly competent engineers, scientists, project and people managers who I count as some of the best of the best in their respective fields. To become one of the best, you &lt;em&gt;usually&lt;/em&gt; have to enjoy your work. It’s very hard to force yourself into excellence. That said, it &lt;em&gt;is&lt;/em&gt; possible to excel at your profession without enjoying it, as long as you have a strong enough meaning or purpose to the work that you do – a &lt;em&gt;why&lt;/em&gt; that overpowers the &lt;em&gt;what&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Generalizing this notion a little, I’ve entertained the thought for a while now that in order to find happiness in what you do and improve at it, you either need to find joy in your work, or find meaning in your work. You can have both and you can have neither, each with its own outcome. Below is a little matrix illustrating roughly what I believe each combination of joy and meaning leads to.&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;Learning Curves&quot; src=&quot;/images/work/chart.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Without a doubt enjoying the activity that fills the majority of your day and the majority of your week – what constitutes “work” for many of us – is the most powerful catalyst for personal happiness and professional improvement. Given that we spend so much of our adult life “at work”, it goes without saying that if your work is something you truly enjoy, something you would be doing even if nobody asked you to or paid you money for, something you would do on your off days and weekends – you would be pretty happy. Find me a person who says no to that and I’ll show you a masochist. In addition to this, when a person who enjoys her work is also ambitious, competitive and driven, this naturally fosters an interest in self-improvement. If you love what you do and take pride in your skill and becoming continuously better at it, the urge to improve, learn and refine comes naturally.&lt;/p&gt;

&lt;p&gt;That said, enjoying your work without having a meaning or purpose, an &lt;em&gt;end&lt;/em&gt; to your work – can also be a form of &lt;em&gt;hedonism&lt;/em&gt;. I really enjoy eating food and becoming a professional food eater would likely bring me quite a lot of joy. I might even strive to become the best food eater there is. However, I’d be hard pressed to explain what purpose I’m aiming to achieve with my profession and my relentless ambition beyond satisfying my gluttony. Simply put, if you already love what you do, &lt;em&gt;why not&lt;/em&gt; apply it to something useful to society, your community, your family or even yourself – enabling some higher, more meaningful goal you seek after.&lt;/p&gt;

&lt;p&gt;Let’s consider the other axis: meaning. There are individuals who don’t particularly enjoy – even dislike – their day-to-day work, but find some &lt;em&gt;meaning&lt;/em&gt; in their occupation that drives them. That drive will not breed the same happiness as obtained by the person who actually enjoys their work, but the deep rooted purpose they’re pursuing can very well foster the same determination to continuously improve and strive for excellence. Consider a medical researcher who aspires to find a cure for cancer. They may not enjoy the ardor of lab work day in and day out. They may have things they’d rather be doing on a sunny Saturday afternoon. Yet their passion to accomplish their goal pushes them to constantly improve, to read dozens of papers every week, to learn the latest methods, improve on them and surpass the boundaries of their medical knowledge. Having meaning to one’s work can be a fertilizer for improvement, even if it is not a fertilizer for happiness.&lt;/p&gt;

&lt;p&gt;I think a lot more people find meaning in their work than joy. Anybody who regards their work as a way of “bringing home the bacon” to support their family, their hobbies or other aspirations, has a purpose to their work. Anybody who ever put in extra hours to rake in a promotion to get a higher salary has gotten a taste of the effects of having meaning to one’s labor. However, at least for me, “making more dough” is a pretty weak purpose. The higher up Maslow’s hierarchy of needs my purpose is, the harder I’ll strive to make ever faster progress towards that goal.&lt;/p&gt;

&lt;p&gt;Discontent arises when you neither enjoy your work, nor find it meaningful. At the macro scale I have fortunately never experienced this, but at the micro scale I have. Most likely all of us have had to do some annoying task for no apparently good reason and hated every minute of it. It not only breeds unhappiness, it also doesn’t motivate us to improve ourselves at our work, unless it means that we can get it over with sooner – which only goes so far and is only so sustainable. Realistically, if you find that your work is a torture, if you can find neither joy, nor any meaning to it, you need a change. Your prospects are either personal misery, professional stagnation or, most likely, both. Life is a short ride, way too short to spend it like that.&lt;/p&gt;

&lt;p&gt;That brings us to the final of our four cases, lined in gold and sparkling with diamonds: the top right quadrant, when your work brings you both joy and meaning. I can’t claim that it’s like this for me every day, but from personal experience there is little more electrifying than working on something that you generally like to do, that is fun to you in its own right, but also gives you the feeling of edging you closer towards some higher purpose. It’s the kind of stuff that makes sleep your enemy, because it takes away precious time that you could be spending on what you love to do and feel like you &lt;em&gt;need&lt;/em&gt; to do. It’s what spawns an insatiable appetite for personal growth, for reading every article and every book and talking to every person out there that could help you grow. It’s what separates the truly great from the very good, and the truly happy from the very content.&lt;/p&gt;

&lt;p&gt;I’ve found that joy and meaning are two very salient parameters by which to characterize one’s work and I’ve seen plenty of folks in all four spots. It helps to periodically check in with yourself where you currently see yourself and take appropriate action. If you find both joy and meaning in your current day to day occupation, good for you and keep it up, strive further and further into that top right corner, off the charts. If your work brings you joy, but you cannot honestly discern a meaningful purpose to it, you may have become too complacent and it’s time to &lt;em&gt;apply&lt;/em&gt; what you love to a higher goal. If you think your work has purpose but you do not enjoy it, consider whether you can change the latter. Life is better with a smile. If not, hats off to you, you must be a disciplined person and your purpose must be honorable. But if none apply, if Monday morning is the worst part of your week and you feel like the world would really not be a whole lot different, maybe even better off, if you didn’t continue what you’re doing for another 40 years, it’s time for a change. We all have potential and we all deserve a fair shot at happiness.&lt;/p&gt;
</description>
        <pubDate>Sun, 01 Nov 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/thoughts/work/2020/11/01/16-54-48-finding_joy_or_meaning_in_your_work/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/thoughts/work/2020/11/01/16-54-48-finding_joy_or_meaning_in_your_work/</guid>
      </item>
    
      <item>
        <title>Of Hammers And Nails: Solving The Right Problems</title>
        <description>&lt;p&gt;The world of technologists is an exciting bubble. Few other groups make such strong claims to a monopoly of power to alter the world for the better. From the inside, Silicon Valley can feel like a utopia factory. In place of molten iron flowing into blast furnaces to forge steel, ideas on whiteboards and mathematics flow into code editors and onto the app store to make the world a better place.&lt;/p&gt;

&lt;p&gt;One could argue that this sense of importance is justified. Since the dawn of the ages, technology in its most general sense, and in the last century information technology in particular, has made the world a better place. Despite the doom and gloom we are accustomed to from newspaper headlines every day, today’s generation has it good. The standard of living across the globe is higher than it has ever been in the history of mankind. On average people live longer and are healthier, richer, better fed, more educated, less affected by war and conflict, less dependent on the circumstances of their birth as a determinant of their future and, most importantly, enjoy more freedom than ever before. Innovations in medical, industrial and computer technology are to thank for many of these improvements. A little self-congratulation for us technologists is not out of place.&lt;/p&gt;

&lt;p&gt;Besides past laurels, novel technology can simply seem very exciting. Virtual Reality seems pretty cool. Blockchains seem also cool. Chatbots seem very cool too. And more than anything, artificial intelligence is about the coolest thing sliced bread. Wow! So cool! In fact, few other fields have received as much attention and have had expectations for its ability to aid humanity rise so high as AI. Having worked at one of the top AI research labs during peak hype, I know what it feels like to work on a technology that people expect to elevate mankind and be surrounded by people who believe strongly in this.&lt;/p&gt;

&lt;p&gt;Unfortunately, I often sense a disconnect between the excitement for technology exuded by technologists — myself included — and the problems the world and its inhabitants actually face. Blockchains haven’t lifted people out of poverty, they’ve instead made it easier for organized crime to launder money. Virtual reality hasn’t made it easier for doctors to perform heart surgery yet and still fails to attract legitimate interest from anybody but ardent gamers. Chatbots have become a great interface to dial up a human being who can actually help you with your problem. Even AI has, in my opinion, yet to live up to its very high expectations. It has without doubt delivered plenty of valuable improvements to our lives: somewhat-self-driving cars, faster shopping with Amazon Go, fantastic language translation, more tailored internet content and safer borders (my current line of work). But I would shy away from calling any of these more than “incremental” in the grand scheme of human happiness and societal progression.&lt;/p&gt;

&lt;p&gt;A few years ago a friend shared a metaphor with me that struck right into the midst of this issue and has stuck with me ever since. The “technologists trap” is often to invent a new, advanced form of hammer and then proceed arduously to seek nails that can be hammered with this exciting new tool, only to find that nobody really needed this new hammer or that the nails that fit the hammer are not of such great importance. AI is a perfect example. It may well be the shiniest hammer ever forged and upon its discovery thousands of the best and brightest rushed out looking under rocks for nails to hammer with it. Might businesses want chatbots on their website? What if doorbells could tell you who’s ringing? Could we replace this and that task with AI?&lt;/p&gt;

&lt;p&gt;I like the metaphor of the hammer and nail because I think it points out the problem quite well. I believe the approach of saying “I have this new hammer, what nails can I hammer with it” meaning “I have this new technology, what problems can I solve with it” is somewhat backwards. It puts emphasis on the technology rather than on solving a problem. The world fundamentally doesn’t need more exciting technology, it needs fewer problems.&lt;/p&gt;

&lt;p&gt;Let’s consider the alternative approach: you identify nails and develop a hammer for them. Take the Spinning Jenny, a key development during the industrial revolution that greatly multiplied the output of cotton production in 18th century England. James Hargreaves, its inventor, did not come up with some hyped-up new tech and then went on a search for who might find it useful. He first identified the problem that cotton factories struggled to match their output with the demand for cloth and then went about to build a solution for it, which subsequently revolutionized the textile industry.&lt;/p&gt;

&lt;p&gt;Elon Musk is another good example of someone who took the nails-first approach. In &lt;a href=&quot;https://soundcloud.com/startalk/patrons-only-elon-musk-extended-interview&quot;&gt;an interview&lt;/a&gt; he gave a few years ago, he stated that when he was in college, he asked himself “what are the things that are most going to benefit the future of humanity”. He settled on electric cars, solar power and, later on, space exploration. He then went ahead and built successful ventures that addressed each of these problem spaces, using technologies available at the time and improving them – &lt;em&gt;monumentally&lt;/em&gt; – as necessary to reach his goals. He didn’t stop there either. Upon identifying the troubles of America’s transportation system, he promptly devised &lt;em&gt;two&lt;/em&gt; new solutions with his &lt;a href=&quot;https://en.wikipedia.org/wiki/Hyperloop&quot;&gt;Hyperloop&lt;/a&gt; and &lt;a href=&quot;https://www.boringcompany.com&quot;&gt;Boring Company&lt;/a&gt; ideas. Elon Musk gets it.&lt;/p&gt;

&lt;p&gt;Fortunately, the free market does its part to regulate the technologist’s trap. By the will of the people and the invisible hand of the market, companies that provide insufficient value, whose solutions don’t solve real problems, are eliminated. The hammer and nail analogy translates quite nicely beyond technology and to business in general. I recently learned this myself when some friends and I came up with a business idea. We thought we had a great solution for a certain market niche. When we subsequently talked to people, we found that few actually had the problem our solution was solving. We had an exciting hammer, but failed to find any nails.&lt;/p&gt;

&lt;p&gt;Even if one does find suitable nails to hammer, or one does convince the other party that they really have the sort of problem one’s solution addresses, it still leaves the question whether that problem is actually the right one – the &lt;em&gt;really important&lt;/em&gt; one – to solve. Unfortunately, market value and societal value are not the same. There are numerous examples of companies that have grown rich on the basis of some popular but not particularly enlightening technology. The market rewards them for the value they provide to their customers in the form of entertainment, convenience, pleasure or otherwise. That does not mean that their innovations have advanced mankind or bettered society. Just because they found nails that fit their hammer, does not mean that those were the nails that really needed hammering.&lt;/p&gt;

&lt;p&gt;The age-old adage has it right: Necessity is the mother of invention. Invention should not be the mother of necessity. Let’s not see problems where there aren’t any. There are enough problems out there begging for solutions. So why not try Elon Musk’s approach and ask ourselves what the biggest challenges facing humanity are today and will be tomorrow. When I ask myself this question, I find that all problems I can think of boil down to the following three basic necessities for a happy, fulfilling life on earth for humans:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Health&lt;/li&gt;
  &lt;li&gt;Freedom&lt;/li&gt;
  &lt;li&gt;Opportunity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are plenty of problems in each of these areas:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The eradication of disease (health)&lt;/li&gt;
  &lt;li&gt;The efficiency, affordability and accessibility of education (opportunity)&lt;/li&gt;
  &lt;li&gt;Equality and accessibility of economic opportunities regardless of origin, race and gender (opportunity)&lt;/li&gt;
  &lt;li&gt;Freedom of thought, expression and enterprise (freedom)&lt;/li&gt;
  &lt;li&gt;War, terrorism and crime (freedom, opportunity)&lt;/li&gt;
  &lt;li&gt;Drug addiction (opportunity)&lt;/li&gt;
  &lt;li&gt;Space exploration (opportunity)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These, I think, are the really thorny problems of our time. I want technology to solve these problems, not to produce another TikTok. Many of these may seem like policy issues, addressable more by government and politicians than killer apps and websites. However, here the technologist in me comes back to life and makes the claim that technology has, again and again, been a strong vector for change in all parts of our society. I believe technology &lt;em&gt;can&lt;/em&gt; forge the right tool to hammer these nails. We sure as hell should give it a good shot.&lt;/p&gt;
</description>
        <pubDate>Sat, 26 Sep 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/thoughts/2020/09/26/23-32-07-of_hammers_and_nails-_solving_the_right_problems/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/thoughts/2020/09/26/23-32-07-of_hammers_and_nails-_solving_the_right_problems/</guid>
      </item>
    
      <item>
        <title>Making the World Smaller: Facebook, Internships</title>
        <description>&lt;p&gt;This anonymized email correspondence is part of my series on “Making the World Smaller”. See the &lt;a href=&quot;https://www.goldsborough.me/learning/2020/08/09/15-22-26-how_we_learn-_people,_trial_and_error/&quot;&gt;introductory post&lt;/a&gt; for context.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hey Peter!
I read the article on your site about your Facebook internship, and was in awe when you said you wrote 30k LOC.&lt;/p&gt;

&lt;p&gt;I’m currently interning at Facebook too, and have been trying to be more productive, but even though I’m happy with how much I’m outputting and I think I ramp-up decently fast, I’m nowhere near the area code of 30k LOC, and I’m really curious how you were able to write so much. &lt;/p&gt;

&lt;p&gt;I’m entering into my midpoint review and have completed most of my summer project, but feel like I haven’t written much. I didn’t really care about LOC much before coming here, but my mentor has been hinting how prevalent it’s used to evaluate interns so I’m trying to be more productive. &lt;/p&gt;

&lt;p&gt;I actually plan to drop out of school if I get a return offer, so though I know LOC isn’t a perfect metric, I want to exceed as many metrics as I can. Since I don’t plan to have a degree, both for my self-esteem and for whenever someone points out I don’t have a degree, I want to be able to point to this point of my life and say “hey I killed that, I’m good at building software, I have the knowledge and ability” by anyone’s metrics.&lt;/p&gt;

&lt;p&gt;I’m curious about your internship, the scope/scale of your work seems massive, were you able to work 8 hour days? How quickly did you ask for help to get unblocked instead of diving into docs? How did you write 30k lines, and how many of those lines were your main summer project vs stretch goals?&lt;/p&gt;

&lt;p&gt;Sorry for all the questions, but I’m really interested in your experience and thanks.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Let me try to answer your questions. Three years is a bit of time so I don’t remember a lot of details of my performance. I don’t even remember that I wrote that much code. For one, it really is a stupid metric and you certainly shouldn’t base your self esteem on your LOCs. I’ve been 2x intern manager now and yes, LOC is one metric we have to compare intern productivity in calibrations. We kind of have to use it because we only have 12 weeks to evaluate interns and so we need every signal we can get. But let’s be clear that LOC depends heavily on what language you’re using and the complexity of your project. If I tell intern A to write some tests for a class they may generate 1000 LOCs in one week. Another intern B I might tell to understand ShardManager settings and figure out how to configure some load balancing constraints, which will amount to about 5 LOCs in Configerator after a week of learning. Intern B probably learned more and became a better software engineer in that week than did intern A, and intern B may have landed a 10% decrease in cpu utilization across the tier which will earn him major impact while nobody gives a shit about those 1000 LOCs of test code — they’re just good to have. So don’t delude yourself that writing 30k LOCs is the only thing you need to get right.&lt;/p&gt;

&lt;p&gt;On that point, intern performance has 5 axes for a good reason. Software engineering is not just emitting code into an IDE. Productivity is one axis, LOC is one way to measure productivity. The other axes are just as important, in particular Initiative &amp;amp; Independence and Communication &amp;amp; Collaboration is where great interns set themselves apart from good or mediocre interns. Quality of Work and Learning Speed is also very important. Here are some examples of how you can set yourself apart in these axes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Initiative &amp;amp; Independence: Think outside of your project, think outside the box. Be proactive. Projects are never set in stone. Become a member of the team, not just an intern. A member of the team wouldn’t take task after task in his/her project. A member of the team would question what is the best way to arrive at some solution, and what else can be done outside of that solution to help the team and drive the mission forward. Do things that people don’t ask of you. Suggest ways that the project could be altered to overshoot the project. Own your project. In the last few weeks of my internship I was effectively driving my own time. I had things on my mind that I wanted to do to help the mission and my manager no longer had to tell me what to do. This axis is the one that sets rockstar interns apart from the other 3988 interns each summer.&lt;/li&gt;
  &lt;li&gt;Communication &amp;amp; Collaboration: Again, become a member of the team. Not an intern. By the end of the internship people should treat you as an FTE and not an intern. That, literally, is also the point of the internship. You’re expected to be an E3 engineer that could be put onto the team the day your internship ends. That also means communicating and collaborating with your peers. Participate in meetings, participate in brainstorms. Bring ideas to the table. And post, post a lot. Post all the time until people tell you to stop (which they won’t).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quality of Work is important too and it kind of connects to learning speed. You’re expected to be able to pick up things quickly and that includes style guides and suggestions that people make to your code. Try to never receive the same comment on your diff twice (w.r.t. coding patterns). In my case I was already kind of an expert in C++ and so I knew more C++ than most people on the team and I also have a greater sense of code quality than most software engineers so my quality of work was good.&lt;/p&gt;

&lt;p&gt;In some sense LOC is not a goal in itself. A large number of LOCs will come from you performing above average in every single axis:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Quality of work will mean your diffs receive few comments and land quickly, reducing your iteration time&lt;/li&gt;
  &lt;li&gt;Learning speed will mean you will understand other codebases, libraries, issues quickly and spend more time executing on tasks (writing code),&lt;/li&gt;
  &lt;li&gt;Initiative &amp;amp; Independence will mean that you will know what needs to be done to complete the next task, maybe because the task was your idea. So you will spend more time coding and less time asking your mentor what to do next,&lt;/li&gt;
  &lt;li&gt;Communication &amp;amp; Collaboration will mean that you will communicate problems effectively with your peers and use your peers’ expertise and knowledge to bounce ideas off of them before you write some code. Because you communicate effectively and early, you will not spend time rewriting some code after putting up a diff and another engineer telling you that your approach is completely wrong which you could have found out by talking to them for 5 minutes before you went ahead with coding.&lt;/li&gt;
  &lt;li&gt;Productivity in the end just means that you’ve done all of the above things right, and now all you need to do is emit characters into your IDE that achieve the goal.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I don’t remember how quickly I unblocked myself. I certainly didn’t work 8 hours a day, I can tell you that much. I probably worked from 10am to 8pm, sometimes midnight. I worked sometimes on the weekend. I definitely burned myself out in the end. But I don’t really regret that. You have three months to impress and land a return offer, so my philosophy tells me that it’s better to spend 12 weeks working my ass off 14 hours a day and then taking a week of vacation in the Bahamas (I wish) than it is to coast through the internship at a comfortable pace. This is not what most people will tell you, but it’s just a life choice you have to make at one point. I was never the smartest kid, I got ahead by working harder. So one factor why I landed 30k LOCs of code is certainly that I made 50% more time to write code where others were doing idk what.&lt;/p&gt;

&lt;p&gt;I’m not sure your idea of exceeding as many metrics as possible will really validate you as a software engineer after you drop out. I don’t know if you already figured this out from my cv or post or whatever, but I dropped out after my internship to join Facebook full time. At the end of my internship my team manager pulled me into a room and offered me a full time offer if I wanted one instead of a return offer. I have three years of experience living with this decision now, and I have no regrets for sure, but I can tell you that nobody checks your performance later on to evaluate your worth… and I don’t think if you write “Wrote 30k LOC” on your CV as a way of making up for lack of a degree will work out in the way you expect. And it will not mean that you’re good at “building software” or that you have “knowledge” or “ability”. So my point is that while I commend your motivation to exceed, to validate yourself as a software engineer, to impress people, I think your strategy of achieving any of that by writing more code is misguided. There’s a lot more required to exceed, to validate yourself and to impress people. I outlined the axes above and you should strive to exceed in each one if you want success and validation.&lt;/p&gt;
</description>
        <pubDate>Tue, 18 Aug 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/mws/2020/08/18/19-07-45-making_the_world_smaller-_facebook,_internships/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/mws/2020/08/18/19-07-45-making_the_world_smaller-_facebook,_internships/</guid>
      </item>
    
      <item>
        <title>Making the World Smaller: Interviews, Google</title>
        <description>&lt;p&gt;This anonymized email correspondence is part of my series on “Making the World Smaller”. See the &lt;a href=&quot;https://www.goldsborough.me/learning/2020/08/09/15-22-26-how_we_learn-_people,_trial_and_error/&quot;&gt;introductory post&lt;/a&gt; for context.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hi Peter,
I hope you are doing great!&lt;/p&gt;

&lt;p&gt;I read your post at your blog about your google internship experience and I wanted to ask you some questions about it if you don’t mind.&lt;/p&gt;

&lt;p&gt;More specifically I want to ask you about the interview, because I am at a similar position you were at that moment. I have an internship interview with google in the following weeks and I haven’t seen yet any of the topics that the interview consists at school (discrete math, algorithms, data structures, etc). &lt;/p&gt;

&lt;p&gt;And although I have quite a bit of experience programming and I’ve been studying data structures and algorithms on my own I don’t feel like I am ready yet, specially after failing an interview with Facebook a few weeks ago .&lt;/p&gt;

&lt;p&gt;In conclusion, these are my questions:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;How was your interview experience, were you able to answer every question?&lt;/li&gt;
  &lt;li&gt;Do you think I should take the interview and have a high chance of failing or wait and reapply next year when I feel more ready?
I feel a bit disoriented, so I would really appreciate your answer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you very much for you time.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hi X,&lt;/p&gt;

&lt;p&gt;Thanks for reaching out. I think getting ready for interviewing is really just about practice and repetition. I remember when I was in this position I started practicing algorithms in August and had my interview around October/November, so I practiced every day for three months (4-8 hours I think).&lt;/p&gt;

&lt;p&gt;I don’t know what your plan for studying is/was, but I started by watching “Introduction to Algorithms” on Coursera and then just worked through “Cracking the Coding Interview” cover to cover. I think the latter will prepare most people for internship interviews.&lt;/p&gt;

&lt;p&gt;To answer your questions:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Yes I was able to answer all questions. I struggled with one but finished them all.&lt;/li&gt;
  &lt;li&gt;I don’t see the benefit of not doing the interview this year. In the worst case you’ll have gained experience and maybe gotten some feedback on where you should improve. You gain nothing from declining this year.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Either way, I think the most important thing to have for interviews is confidence. If you go into an interview thinking you won’t make it, you’re not going to make it. Period. No matter how prepared you are technically, being prepared mentally is just as important. Go into the call knowing you’ll come out with an internship, and then it might actually happen :)&lt;/p&gt;
</description>
        <pubDate>Tue, 18 Aug 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/mws/2020/08/18/19-06-38-making_the_world_smaller-_interviews,_google/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/mws/2020/08/18/19-06-38-making_the_world_smaller-_interviews,_google/</guid>
      </item>
    
      <item>
        <title>Making the World Smaller: Internships, Applying and Making it in Big Tech</title>
        <description>&lt;p&gt;This anonymized email correspondence is part of my series on “Making the World Smaller”. See the &lt;a href=&quot;https://www.goldsborough.me/learning/2020/08/09/15-22-26-how_we_learn-_people,_trial_and_error/&quot;&gt;introductory post&lt;/a&gt; for context.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hi!
I am fascinated by your story about working at Google, Facebok and other companies and love your motto Fix the World. I myself have a small problem with getting an internship as a programmer and I thought maybe you could help me.
I will be 18 years old next summer and I think I have the right skillset to both bring benefit to a company like Facebook and have a chance to pass their interview (actively programming for 5 years now; experienced in problem solving, algorithms, data structures, etc.). Last summer I worked as a software developer for a smaller company.
The problem is that I couldn’t find any way to deliver my CV to their PR other than through their standard forms, which all require at least studying at university (I am at high shool). That leads to them discarding it immediatelly.&lt;/p&gt;

&lt;p&gt;So I was wondering if you know a better way to send my CV to Facebook, or if it is possible at all.&lt;/p&gt;

&lt;p&gt;Thanks in advance and please keep blogging!&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;Thanks for reaching out. Let me see if I can give you some advice or help you out.&lt;/p&gt;

&lt;p&gt;First of all, it definitely is extremely rare for school students to do internships a big tech companies. That probably has a few reasons, including that HR assumes you’re missing important classes/knowledge that you would get in university. Another reason is that internships usually have the purpose of finding potential full-time hires. It’s less beneficial to a company to give someone an internship and invest thousands of dollars in that person, when his/her graduation date is still 4-5 years away.&lt;/p&gt;

&lt;p&gt;That said, you’re lucky you’re in an industry where many of the usual norms and practices, such as requiring formal education or only hiring experienced candidates, are often  broken or redefined. So it’s definitely not impossible to hire an 18-year old, and there have been such cases at Google and Facebook — but they’re very special cases. My own case was sort-of special in that I got into the interview stage with Google right after high school, which doesn’t happen that often (though there was a second guy who interned with me that year who was also in his first year). Thinking back, I think what convinced that recruiter to reach out to me while I was still in school was that I had a quite convincing LinkedIn profile for my age with some research experience, had a fairly active blog and also some pretty large projects going on rather than just a bunch of small projects like most kids do.&lt;/p&gt;

&lt;p&gt;Another thing I can tell you is that it’s much, much harder to get an internship by applying on the website than it is by either (1) getting a referral from someone or (2) being approached by a recruiter. Even when I had the Google internship on my CV, I would often not hear back from online applications. At the same time, I was getting lots of interest on LinkedIn from Microsoft, Facebook etc. and got into the interview stage with all of them. Referrals are also a great way of getting into the process. You just have to know someone at a company, and they can send your CV to certain people. Recruiters will usually look at referrals first before online applications, so your chances of getting noticed are much higher. The person at the company who referred you also gets a money bonus when you get the job, so it’s a great deal.&lt;/p&gt;

&lt;p&gt;So, if you really want, I can send your CV to some people here, and someone will take a look at it. I can’t pledge for your chances, however. I think if I were you, I’d try to get involved with some big open source projects that you’re passionate about, or try to come up with a large project (an app, a library etc.) that many people will find interesting and/or use. These things always look good on CVs. You could also reach out to someone at a nearby university (some professor/PhD student) and ask if you can help them with some research. That’s also great experience.&lt;/p&gt;

&lt;p&gt;I wouldn’t worry about getting the big tech jobs too soon. They’ll come naturally if you stay passionate about programming and are proactive in marketing your skills. When I was your age I definitely wasn’t looking for big tech internships, I was more interested in exploring the possibilities that coding opened to me and was very eager to learn new things. Tech companies are very, very hungry for talent, so you’ll have recruiter emails dropping in your inbox before you know it if you keep doing what you’re doing.&lt;/p&gt;
</description>
        <pubDate>Tue, 18 Aug 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/mws/2020/08/18/19-05-34-making_the_world_smaller-_internships,_applying_and_making_it_in_big_tech/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/mws/2020/08/18/19-05-34-making_the_world_smaller-_internships,_applying_and_making_it_in_big_tech/</guid>
      </item>
    
      <item>
        <title>Making the World Smaller: Facebook, Internships, Software Engineering</title>
        <description>&lt;p&gt;This anonymized email correspondence is part of my series on “Making the World Smaller”. See the &lt;a href=&quot;https://www.goldsborough.me/learning/2020/08/09/15-22-26-how_we_learn-_people,_trial_and_error/&quot;&gt;introductory post&lt;/a&gt; for context.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;My name is X. I’m pursuing a Bachelor’s Degree on the east coast of America, studying Math and CS in my second year. &lt;/p&gt;

&lt;p&gt;First of all, I hope it isn’t awkward for me to email you out of the blue. I’m an avid reader of your blog; it’s taught me a lot and really pushed me forward to try new things in CS, especially in our mutual areas of interest. Like you, I also enjoy studying topics like compilers, distributed systems, and low-level networking, and wanted to hear some more about your experiences!&lt;/p&gt;

&lt;p&gt;For the upcoming summer, I am set to be an SWE intern at Facebook in Menlo Park; I’m really looking forward to it, because I’ve never worked on a codebase that’s as heavily-scaled and ambitious as some of the projects at Facebook are!&lt;/p&gt;

&lt;p&gt;To tell you a bit about myself:&lt;/p&gt;

&lt;p&gt;My tentative area of expertise thus far is within the scope of languages like C++, Rust and Haskell (though I do enjoy a good bit of Python here and there!) Given this, I’m currently planning to pursue placement on an infrastructure team. I’ve read extensively about some of the prevailing practices and projects at Facebook through its open-source presence and through the experiences of yourself and other prolific engineers and blogger, and can’t wait to get started!&lt;/p&gt;

&lt;p&gt;Personally, I find myself to be a generally carefree and fun-loving person, especially when it comes to code and life. I sometimes have a hard time focusing if a project or a subject matter doesn’t interest me, but I’m downright obsessive when something catches my interest; in this case, I cannot help but think day and night about how I can make it better.&lt;/p&gt;

&lt;p&gt;To be completely honest, I’m also immensely overwhelmed with the magnitude of some of the things Facebook does. Most of my past internship experience has been low-impact work for small startups, along with a relatively haphazard assortment of scripts and programs I write for hackathons, and I’ve definitely never experienced anything like this!&lt;/p&gt;

&lt;p&gt;I was hoping to discuss the following points:&lt;/p&gt;

&lt;p&gt;1) Naturally, I’m very eager to learn how things go by and people become successful at an environment like Facebook. My very big ambitions spike intermittently with my fun-loving nature, it seems, and I also experience a desire to change the world and accelerate human progress with code and new ideas. Therefore, it’s expected that I’d ask:&lt;/p&gt;

&lt;p&gt;What were some of the most valuable things you learned during your own Facebook internship? How do you feel that those impacted you as an engineer and scientist in the long term? Finally, is there any general advice you would have for someone in my shoes?&lt;/p&gt;

&lt;p&gt;2) As I touched on a bit in (1), I find myself motivated not only to code and have fun, but also to make the world a better place. The magnitude of my ambitions necessitates that I pursue greatness, however one may define that, in engineering and science. Therefore:&lt;/p&gt;

&lt;p&gt;What, in your experience, separates the good developers from the great ones? What is the standard that you set for yourself, professionally, and why did you choose it? How has it pushed you forward as an engineer?&lt;/p&gt;

&lt;p&gt;Thank you so much! It’s been great reading your thoughts on your blog, and I look forward to hearing from you!&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hi X,&lt;/p&gt;

&lt;p&gt;Sorry for the delay. Nice to meet you and I’m glad you like my blog!&lt;/p&gt;

&lt;p&gt;I think the most valuable things I learned during my internship at Facebook that influenced me today were probably less related to new knowledge. For example, I had worked on large codebases before, but that might be a very exciting experience during your internship. I learned a lot more about elements of “being a software engineer” which includes how to manage your time, what efforts to prioritize and which not to, and how to seek out the most impactful work. Facebook is a heavily impact-driven company, which means it values efforts which improve things substantially, rather than rewarding things just because they “took a lot of work”. Most importantly this means it does not matter how long or how hard you work, it only matters how smart you work and what you achieve. What separates experienced software engineers from ones fresh out of college is often times how they manage their time and work. Why is that senior engineers come in at 9 AM and go home at 5 PM to get their kids of out school and spend half their day in meetings, and yet still seem to get more done and have more impact that 23-year olds who work 12 hours. So one thing I learned is to understand the difference between hard work, and impactful work. The other thing that was really important during my internship were my social interactions with my teammates. I had great relationships with my intern manager (mentor) and team manger and yearned advice and feedback wherever I could. Not just on professional things (“how would you solve X?”) but also personal things (“how do I manage my time better?”). I would recommend you really make the most out of your relationships with your team and take them seriously. Some of them will have 10 years more experience than you. They’ve lived through all professional challenges you still have in front of you. Take this opportunity to ask them questions. Also make the most out of your meetings. Don’t just wander in them without anything planned. Make a list of things you want to talk about/that are on your mind. This reminds me: one thing I learned was the importance of finding the very fine line between when you should just figure it out yourself given the resources available (e.g. code search) and when you should ask a question because you’re stuck. If you observe senior engineers, they rarely ask questions about the codebase and such, not because they don’t have questions, but because they know how to find answers without using other engineers’ time.&lt;/p&gt;

&lt;p&gt;I think the above blob also kind of covers your second question. Great engineers get more done in less time, know how to prioritize impactful work. Down the line mentoring becomes very important, but that’s not relevant right now.&lt;/p&gt;

&lt;p&gt;Hope that helps. If you have more specific questions let me know.&lt;/p&gt;

&lt;p&gt;Peter&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;A follow-up to this email: I gave it another read when I felt like I was coming onto another question.&lt;/p&gt;

&lt;p&gt;You mentioned mentorship as being very important in your career. Obviously, I’m hoping for a great relationship with my intern manager (haven’t been introduced yet, should be this month or next,) but I’d also like to meet a lot of people in a lot of different teams and subdivisions.&lt;/p&gt;

&lt;p&gt;Strictly pertaining to the internship, I’d like to, if possible, be on multiple different projects than just the one I’m being evaluated on for my primary intern manager. The ten weeks I’m given seems like precious little time to do everything I’d want to do; I would, if anything, prefer to work a few extra hours each day so that I could experience more than just one project with one team. Without overextending myself, how would you suggest that I grow into a role of wearing a lot of hats, working on a lot of different and impactful things, and meeting a lot of different people?&lt;/p&gt;

&lt;p&gt;Thanks in advance! Please take your time, but I’m looking forward to hearing from you again!&lt;/p&gt;

&lt;p&gt;Hope you are well!&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hey,&lt;/p&gt;

&lt;p&gt;First of all, I think the number one thing during your internship is to do your project well. If you’re doing lots of projects but your main one is lagging that won’t reflect well in your review, just like if I’m assigned to a project for a half and spend all my team on side projects, that will raise some red flags. Remember also that you only have ten weeks, and ramping up takes time. Depending on what your project will be, you’ll be faced with very many and individually complex systems that take some time to learn. When new engineers join Facebook full-time, they get 6 weeks of basic training to learn (a small portion of) Facebook’s tech stack. As an intern, you have about one to two weeks to “ramp up”, after which you should probably start getting comfortable with whatever tools you’re using. So just keep in mind that your main project is the most important thing. If you do your main project well and don’t do any side projects, you’ll probably get a return offer. If you do many side projects but your main project not so well, you might not.&lt;/p&gt;

&lt;p&gt;Now, that’s just the disclaimer. If your main project is going well, you can of course expand into other areas. I was actually quite active on that front, and I recall recruiters saying that interns who do exceptionally well generally do some additional things next to their main project. One great opportunity to have impact “on the side” and also experience Facebook culture is to participate in a hackathon. I’m sure there will be one during your internship time. They’re a big part of Facebook and a great way to meet people, work on cool, innovative ideas and show some additional impact. If your project is really cool, you also get to meet Mark Zuckerberg.&lt;/p&gt;

&lt;p&gt;Another way of reaching out to different teams is having some unique area of expertise that may be helpful to other teams. For example, at the time of my internship I was somewhat of an expert on compilers and static analysis, so I gave a tech talk on that stuff and one guy from the code search team reached out to me and invited me to their team meetings. That looked pretty good on my review too.&lt;/p&gt;

&lt;p&gt;Lastly, if there’s any particular project you’re very interested in, there’s nothing stopping you from just reaching out to to that team and asking for small (or medium) tasks to work on in your after hours. In fact, since the whole Facebook codebase is open, you can just send contributions without even asking (although you might as well talk to them first). Engineers always have extra work on their plate that they’re happy to delegate, and it might be a great learning experience for you and something you can write in your review.&lt;/p&gt;

&lt;p&gt;I would recommend spending your first 3-4 weeks ish focusing just on your project and nothing else, and if you feel comfortable enough after that you’ll have another 6 weeks to expand. Also be sure to ask this same question to your manager and he/she may give you more advice or even introduce you to other teams in the org that could have some additional work for you.&lt;/p&gt;

&lt;p&gt;Best
Peter&lt;/p&gt;
</description>
        <pubDate>Sun, 09 Aug 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/mws/2020/08/09/16-11-50-making_the_world_smaller-_facebook,_internships,_software_engineering/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/mws/2020/08/09/16-11-50-making_the_world_smaller-_facebook,_internships,_software_engineering/</guid>
      </item>
    
      <item>
        <title>Making the World Smaller: Internships, Getting Noticed, Getting Started in Industry</title>
        <description>&lt;p&gt;This anonymized email correspondence is part of my series on “Making the World Smaller”. See the &lt;a href=&quot;https://www.goldsborough.me/learning/2020/08/09/15-22-26-how_we_learn-_people,_trial_and_error/&quot;&gt;introductory post&lt;/a&gt; for context.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hi Peter,&lt;/p&gt;

&lt;p&gt;First of all, congratulations for what you have accomplished so far! I have red a couple of posts as well as your CV on your blog. The internships and jobs that you have gotten are something that I think many dream about and so do I.
I am currently 19 years old and will start studying computer science in the coming winter term. Since I will have to (and want to) do internships in tech-firms later I thought that you could definitely give my some helpful advice on how to set myself up to get internships.
For instance, what do you consider most important about internet appearance? Having a LinkedIn profile, having your own blog … ? And since you work in machine learning as well, did you do Kaggle competitions?&lt;/p&gt;

&lt;p&gt;A response would be highly appreciated!&lt;/p&gt;

&lt;p&gt;Thanks and best regards&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hi X,&lt;/p&gt;

&lt;p&gt;Thanks for your email. Nice to meet you.&lt;/p&gt;

&lt;p&gt;I think the three things that made a difference early on in my career were my internet presence, the many personal projects I did, and the fact that I engaged in research projects from an early age. The two main factors that recruiters look at in intern candidates are: job experience and extraordinary coding experience. Once you have those, you just need to get noticed.&lt;/p&gt;

&lt;p&gt;Extraordinary coding experience can manifest itself in one of two ways: competitive coding accomplishments, or personal projects. I was never interested in the former, and always very excited about the latter. I loved building things and expanding my skills by working on small and contained libraries, GUI projects and hardware stuff (electronics). As a consequence, I also became very good at programming, especially when working on real world projects. Competitive coding is useful to learn about algorithms and pass interviews, but useless for everything else in software engineering. So this part of my activities a couple years ago ticked the “extraordinary coding experience” box. You mentioned Kaggle: I never did it myself, though I imagine that would look good to. However, in my opinion, it’d be cooler to solve real world problems with machine learning. Like, build an app that you can point at a tree and it tells you what kind of tree that is. This will be 100x harder than an equivalent Kaggle challenge, since you not only have to solve the machine learning bits, but also all the infrastructural challenges around how to develop and distribute the application. It’s kinda like solving a competitive coding problem on HackerRank will teach you about a particular algorithm, but using that algorithm in a real world application or even packaging it in a distributable library that you dump on GitHub for others to use will teach you so many more valuable skills.&lt;/p&gt;

&lt;p&gt;Getting job experience is very hard early on, and as I’m sure you know it’s a bit of a chicken and egg problem (you need experience to get experience). Once you’ve done a single internship with a big company like Facebook, Google, Uber, Microsoft, Palantir or a few others, all your problems kind of go away, as other companies will flock to hire you, given you’ve proven yourself in one of these internships already. So how do you break into this loop? The way I did it was by working on research projects at my local university. The thing is that academics (professors, PhD students, even masters students) always have a ton of work, and are happy to get any kind of help from students. For them, it’s just free labor, and for the student, it’s fantastic experience and can even lead to a publication. Either way, if you have no other or only limited job experience, research is a great way to prove that you can work on big projects. Another easy way to get job experience is startups or small companies, at least from what I’ve heard. Either way, it’s important to be pro-active in this regard. Just spam people (nicely) and say that you’re interested in working for them. Don’t care about money for now, only care about experience (but also don’t work for free!).&lt;/p&gt;

&lt;p&gt;So, say you have sufficient job experience and a way of proving extraordinary coding experience. Now you only need to get noticed. For this, yes, LinkedIn is important. LinkedIn is less interesting to me know because I have the job I’ve been working towards getting for many years, but a year or two ago it was very important for getting contacts. Whenever you  meet someone, at a conference, or through friends, or any other way, remember their name and when you get home, add them on LinkedIn. Maybe they work at a company you’re interested in, then you can always message them on LinkedIn to ask for a referral. Then, blogging. I’ve had a blog since I was 16, and it’s always been a very crucial weapon in building my career. People notice it, read it, share it, and not just people like you, but also software engineers looking for interns, and recruiters will usually also take a look. So definitely get one and start blogging. Technical writing is also a very important skill that few people actually master, so it will help you with that. Finally, go to lots of conferences. Go to local meetups for programming languages in your town, travel to conferences, and don’t ever be shy to talk to people. This is so important. Develop the ability to walk up to a random stranger and start a conversation. Also get business cards. I’ve met thousands of useful contacts at conferences over the years, and they’ve opened up so many doors. Once you have the skills, people are the number one way of getting an internship. After actually being good at coding, it’s all about the people you meet and stay in touch with. It makes all the difference, I assure you.&lt;/p&gt;

&lt;p&gt;Let me know if you have more questions!&lt;/p&gt;
</description>
        <pubDate>Sun, 09 Aug 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/mws/2020/08/09/16-09-58-making_the_world_smaller-_internships,_getting_noticed,_getting_started_in_industry/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/mws/2020/08/09/16-09-58-making_the_world_smaller-_internships,_getting_noticed,_getting_started_in_industry/</guid>
      </item>
    
      <item>
        <title>Making the World Smaller: Google, Internships, Going Above and Beyond</title>
        <description>&lt;p&gt;This anonymized email correspondence is part of my series on “Making the World Smaller”. See the &lt;a href=&quot;https://www.goldsborough.me/learning/2020/08/09/15-22-26-how_we_learn-_people,_trial_and_error/&quot;&gt;introductory post&lt;/a&gt; for context.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hi Peter!&lt;/p&gt;

&lt;p&gt;I’m X, a sophomore at Yale University majoring in CS, and I’ll be interning at Google Mountain View this summer. It’s my first ever software engineering internship, after taking my first CS class first semester of college, so I’m both excited and nervous. I have been reading your blogs about your various tech internships and have been really inspired by your work ethic, open mind, and humor. Thank you so much for sharing your experience and wisdom with newbies like me!&lt;/p&gt;

&lt;p&gt;One thing I find particularly admirable about your experience at Google is that you not only did your assigned project, but took the initiative to do projects with other teams. I was wondering if you wouldn’t mind sharing with me how you managed to do it (both getting the projects in the first place, and how you managed to fit them into your schedule). I’m asking because while I find the work of my current team important and worth learning (Search Infrastructure), my true interest is in machine learning (especially NLP). It would be ideal if I could apply my NLP knowledge in real-world engineering setting, such as doing a side project with another team at Google. Your experience would be highly valuable to me!&lt;/p&gt;

&lt;p&gt;I hope I wouldn’t be taking too much of your time. Thank you in advance for your reply!&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Hi X,&lt;/p&gt;

&lt;p&gt;Nice to meet you and thanks for your compliments on my blog, I’m glad you like it. Congrats on your internship.&lt;/p&gt;

&lt;p&gt;For your question: In my case the other team I worked on was our sister team, so I knew the people and that made it easier to eventually be like “hey why don’t you work on this with us”. It sounds like in your case the team you’re interested in is not directly in touch with your current team. Nevertheless, I think the only thing really stopping you from reaching out to a team working on something you’d like to do is your hesitation to do so. To give you some reassurance: Now that I’m full-time for a while, I can say that if an intern sent me a message asking for some task to work on just because they’re interested, that would not be a problem at all. I’d be happy. We (FTEs) all have huge piles of work lying around and often times it’s exactly the easier-to-understand tasks that would be great for someone to just poke around and get some experience, that get pushed aside in favor of higher priority stuff. So I would recommend you just check out some teams or even some folders in google3 that look interesting to you, and then find a POC (e.g. the person who last edited cool_nlp_thing.py) and explain that you’re interested in contributing a little. As an aside, this will also help you immensely if you wanted to do another internship at Google next year and then work on that team.&lt;/p&gt;

&lt;p&gt;The only thing you’ll have to figure out is when you want to do the extra work. You can always do it in evenings/weekends if you feel motivated. In my case I actually finished my main project early, which gave me a couple weeks of just focusing on this additional project. This really depends on your progress in your current project. For example, if you’re expected to complete your project early given your current progress, you could ask your manager if he/she would be fine with letting you work on something else one day out of the week, just like in Google’s 20% policy. You could also maybe take an hour from your main project in the evening, then add on one hour (not going to kill your evening schedule) and suddenly you have two hours a day to work on your other project. Something like that :)&lt;/p&gt;

&lt;p&gt;I hope that helps and good luck with your project(s).&lt;/p&gt;

&lt;p&gt;Peter&lt;/p&gt;
</description>
        <pubDate>Sun, 09 Aug 2020 00:00:00 +0000</pubDate>
        <link>http://www.goldsborough.me/mws/2020/08/09/16-03-10-making_the_world_smaller-_google,_internships,_going_above_and_beyond/</link>
        <guid isPermaLink="true">http://www.goldsborough.me/mws/2020/08/09/16-03-10-making_the_world_smaller-_google,_internships,_going_above_and_beyond/</guid>
      </item>
    
  </channel>
</rss>
