<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Khaja Minhajuddin on Medium]]></title>
        <description><![CDATA[Stories by Khaja Minhajuddin on Medium]]></description>
        <link>https://medium.com/@minhajuddin?source=rss-9173227d41e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8v5C5LdMQ0wKyKkvlmIUwg.png</url>
            <title>Stories by Khaja Minhajuddin on Medium</title>
            <link>https://medium.com/@minhajuddin?source=rss-9173227d41e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:13:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@minhajuddin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Debugging your Phoenix, Elixir and Rails applications inside Docker containers]]></title>
            <link>https://medium.com/tripping-engineering/debugging-your-phoenix-elixir-and-rails-applications-inside-docker-containers-305c9d80ff80?source=rss-9173227d41e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/305c9d80ff80</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[debugger]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[repl]]></category>
            <dc:creator><![CDATA[Khaja Minhajuddin]]></dc:creator>
            <pubDate>Tue, 28 Aug 2018 17:01:02 GMT</pubDate>
            <atom:updated>2018-08-28T17:01:02.016Z</atom:updated>
            <content:encoded><![CDATA[<p>Elixir has a great REPL(iex) which allows you to run arbitrary code and see its results. And the same `iex` can be used to start your mix app with an attached REPL. If you are using phoenix you can get this up by running `iex -S mix phx.server` instead of `mix phx.server`.</p><pre>[info] GET /<br>[debug] Processing with MMWeb.DevController.index/2<br>  Parameters: %{}<br>  Pipelines: [:browser]<br>Request to pry #PID&lt;0.618.0&gt; at MMWeb.DevController.index/2 (lib/mm_web/controllers/dev_controller.ex:7)</pre><pre>5:<br>    6:   def index(conn, _params) do<br>    7:     require IEx; IEx.pry<br>    8:     render(conn, [])<br>    9:   end</pre><pre>Allow? [Yn]</pre><p>You can just hit enter or `Y` and it will drop you into the REPL with the current process’s context, You can now inspect `conn` or `params` or any variable in the current context. This allows you to inspect things in a much more interactive fashion. Once you are done with your debugging you can just enter the `continue` command to let the process continue after the breakpoint.</p><p>Rails has a similar experience using the `pry` gem. You can just add `binding.pry` to a code path where you want to stop and inspect things and it too will stop when it hits the `binding.pry` statement.</p><p>This is all fine and dandy when you are running your applications on your local computer. However, most applications these days run inside docker containers even on developers’ machines, either as a one off docker container or as part of a docker compose script which spins up other dependent applications as individual docker containers. And things become very tricky when you want to use a debugger in these situations. One easy way to latch on to the REPL if you are using Elixir/Erlang is to connect to the BEAM node inside the container from your local computer as a remote shell. And for rails applications, I’ve seen folks start a new rails server on a different port from inside the container just to use the debugger using the docker exec command:</p><pre># from the local computer<br>$ docker exec -it rails_app_container_name /bin/bash<br># now we are inside the container in a bash shell<br>$ rails server -p 8080</pre><p>And once they have this, they target this port and latch on to the debugger through`docker exec`.</p><h4>A better way</h4><p>Thankfully docker provides a better way to do this. When you run a docker container in detached mode (which is what development scripts usually do), you can attach to them by running the `docker attach` command.</p><pre># attach to a running docker container whose name is <br># rails_app_container_name<br>docker attach rails_app_container_name</pre><p>And once you attach to a container it will drop you into the context of your container’s `CMD`. So, if you have a rails server, it will show you the rails logs. However, just doing this doesn’t give you the ability to use `binding.pry` or the debugger. To be able to attach an interactive terminal to a detached container you’ll need to start the containers using `docker run -it` which keeps the `stdin` open (-i, — interactive) and allocates a pseudo-TTY (-t, — tty) for this container. And, if you are using `docker-compose` you’ll have to set it up using the `stdin_open` and the `tty` configuration options.</p><pre>version: &quot;3&quot;</pre><pre>services:<br>  myapp:<br>    image: myapp<br>    stdin_open: true<br>    tty: true<br>    # ...</pre><p>Once you’ve set these up you can attach to your container using `docker attach container_name` and start using your REPLs without any problems. And when you are done with your REPL session you can detach from it by hitting the `Ctrl+P Ctrl+Q` combo.</p><h4>Demo</h4><p>Let us try all of this in a small demo:</p><pre># open a new irb session in a detached container and store its<br># container id<br>container_id=$(docker run --detach --interactive --tty ruby:latest irb)<br># attach to the previous container<br>docker attach &quot;$container_id&quot;<br># run a few ruby commands from irb<br># irb(main):002:0&gt; puts &quot;ruby is great&quot;.upcase<br># ...<br># hit Ctrl+P and Ctrl+Q to detach from this container to get back to your local shell<br># irb(main):003:0&gt; read escape sequence</pre><p>That is all you need to get debuggers working in docker containers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=305c9d80ff80" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tripping-engineering/debugging-your-phoenix-elixir-and-rails-applications-inside-docker-containers-305c9d80ff80">Debugging your Phoenix, Elixir and Rails applications inside Docker containers</a> was originally published in <a href="https://medium.com/tripping-engineering">Tripping Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blazing fast Elixir configuration]]></title>
            <link>https://medium.com/tripping-engineering/blazing-fast-elixir-configuration-475aca10011d?source=rss-9173227d41e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/475aca10011d</guid>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[speed]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[config]]></category>
            <category><![CDATA[benchmark]]></category>
            <dc:creator><![CDATA[Khaja Minhajuddin]]></dc:creator>
            <pubDate>Wed, 22 Aug 2018 17:01:03 GMT</pubDate>
            <atom:updated>2018-08-22T17:01:03.909Z</atom:updated>
            <content:encoded><![CDATA[<p>One awesome aspect of the Elixir community is its pursuit of high performance. So, I set out to benchmark and compare the two common Elixir configuration usages.</p><h4>1. Module attributes</h4><p>An easy way to use configuration is to use module attributes like below:</p><pre>defmodule Request do<br>  <a href="http://twitter.com/timeout_ms">@timeout_ms</a> Application.get_env(:my_app, :request_timeout_ms, _default = 1000)<br>  def get(url) do<br>    HTTPoison.get(url, timeout: <a href="http://twitter.com/timeout_ms">@timeout_ms</a>)<br>    #....<br>  end<br>end</pre><p>However, this approach hard-codes your configuration — Which means your configuration will need to be available at build time and will be embedded in the compiled code. So, the alternative to this is the use of `Application.get_env` during runtime. One other downside of using this is that you won’t be able to change this when the application is running (which may be fine for your use case).</p><h4>2. Application.get_env</h4><p>You can directly call `Application.get_env` from your code to get the configuration data like below:</p><pre>timeout_ms = Application.get_env(:my_app, :request_timeout_ms, _default = 1000)<br>HTTPoison.get(url, timeout: <a href="http://twitter.com/timeout_ms">@timeout_ms</a>)</pre><p>This may seem similar to the previous approach, However in this case the configuration value is read every time this code is called whereas in the case of a module attribute it is read only at compile time. Using this approach allows you to update your environment at runtime and use the updated values the next time they are read. It is by no means slow, as it is backed up by an ets table.</p><p>However, I’ve always felt a bit hesitant while using this in cases with thousands of reads per second because I expected this to be slower compared to module attrs. So, to test my hypothesis I wrote a quick benchmark.</p><h4>The Benchmark</h4><p>We have 2 keys in our config, `:bears` which has 3 strings and `:three_hundred_bears` which has 300 strings like below:</p><pre># config/config.exs</pre><pre>config :benchmark_elixir_configuration,<br>  bears: ~w[ice-bear grizzly panda],<br>  three_hundred_bears: Enum.flat_map(1..100, fn _ -&gt; ~w[ice-bear grizzly panda] end)</pre><h4>The Script</h4><pre># lib/bench.exs<br>defmodule Config do<br>  <a href="http://twitter.com/bears">@bears</a> Application.get_env(:benchmark_elixir_configuration, :bears)<br>  def bears do<br>    <a href="http://twitter.com/bears">@bears</a><br>  end</pre><pre><a href="http://twitter.com/three_hundred_bears">@three_hundred_bears</a> Application.get_env(:benchmark_elixir_configuration, :three_hundred_bears)<br>  def three_hundred_bears do<br>    <a href="http://twitter.com/three_hundred_bears">@three_hundred_bears</a><br>  end<br>end</pre><pre>Benchee.run(<br>  %{<br>    &quot;noop&quot; =&gt; fn -&gt; for _ &lt;- 0..1000, do: :ok end,<br>    &quot;module_attribute_bears&quot; =&gt; fn -&gt; for _ &lt;- 0..1000, do: Config.bears() end,<br>    &quot;Application.get_env_bears&quot; =&gt; fn -&gt;<br>      for _ &lt;- 0..1000, do: Application.get_env(:benchmark_elixir_configuration, :bears)<br>    end,<br>    &quot;module_attribute_three_hundred_bears&quot; =&gt; fn -&gt;<br>      for _ &lt;- 0..1000, do: Config.three_hundred_bears()<br>    end,<br>    &quot;Application.get_env_three_hundred_bears&quot; =&gt; fn -&gt;<br>      for _ &lt;- 0..1000,<br>          do: Application.get_env(:benchmark_elixir_configuration, :three_hundred_bears)<br>    end<br>  },<br>  time: 10,<br>  memory_time: 10<br>)</pre><p>The script is a simple benchee script which runs for 10 seconds. Each function which is benchmarked reads the configuration a 1000 times to avoid<br>the <em>function is too fast</em> warning from benchee.</p><p>It contains 5 variants, here they are with their results:</p><ol><li>`noop`: <strong>24.83μs</strong> for looping a 1000 times without doing anything.</li><li>`module_attribute_bears`: <strong>28.97μs</strong> for reading config using module attributes a 1000 times (which is just a function call)</li><li>`module_attribute_three_hundred_bears`: <strong>29.08μs</strong> for reading a large config using module attributes a 1000 times.</li><li>`Application.get_env_bears`: <strong>427.38μs</strong> for reading application config a 1000 times using `Application.get_env`</li><li>`Application.get_env_three_hundred_bears`: <strong>111.10ms</strong> for reading a large application config a 1000 times using `Application.get_env`</li></ol><p>The benchmarks show that using module attributes is 10x faster than using `Application.get_env`. However, if you look at the actual numbers <strong>using `Application.get_env` takes `0.42μs` to read a single configuration<br>which is pretty darn fast.</strong> So, unless you are reading configuration thousands of times you don’t have to worry about which approach you use and just use whatever is convenient.</p><h4>3. Bonus — Getting the best of both worlds</h4><p>If you want ability to update the environment and also want fast reads you can dynamically compile a `Config` module whenever your configuration changes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb5980af5d3e907e8fc5c614e1905201/href">https://medium.com/media/bb5980af5d3e907e8fc5c614e1905201/href</a></iframe><h4>A few takeaways</h4><p>If you don’t read in from your environment a lot, it doesn’t really make a significant difference which option you choose. For performance sensitive applications that read in from the environment many times per second, then reading in the configuration from a module attribute will give your functions a noticeable boost in performance. However, with a few tweaks, writing a module to handle automatically updating environment configuration is an option for those who want the best of both worlds.</p><h4>The raw results</h4><pre>Compiling 1 file (.ex)<br>Generated benchmark_elixir_configuration app<br>Operating System: Linux&quot;<br>CPU Information: Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz<br>Number of Available Cores: 4<br>Available memory: 7.49 GB<br>Elixir 1.6.6<br>Erlang 21.0</pre><pre>Benchmark suite executing with the following configuration:<br>warmup: 2 s<br>time: 10 s<br>memory time: 10 s<br>parallel: 1<br>inputs: none specified<br>Estimated total run time: 1.83 min</pre><pre>Benchmarking Application.get_env_bears...<br>Benchmarking Application.get_env_three_hundred_bears...<br>Benchmarking module_attribute_bears...<br>Benchmarking module_attribute_three_hundred_bears...<br>Benchmarking noop...</pre><pre>Name                                              ips        average  deviation         median         99th %<br>noop                                          40.28 K       24.83 μs    ±38.58%          23 μs          52 μs<br>module_attribute_three_hundred_bears          34.52 K       28.97 μs    ±37.34%          28 μs          40 μs<br>module_attribute_bears                        34.39 K       29.08 μs    ±24.75%          29 μs          45 μs<br>Application.get_env_bears                      2.34 K      427.38 μs    ±30.05%         358 μs         824 μs<br>Application.get_env_three_hundred_bears     0.00900 K   111169.10 μs    ±23.45%      106147 μs      184344 μs</pre><pre>Comparison:<br>noop                                          40.28 K<br>module_attribute_three_hundred_bears          34.52 K - 1.17x slower<br>module_attribute_bears                        34.39 K - 1.17x slower<br>Application.get_env_bears                      2.34 K - 17.21x slower<br>Application.get_env_three_hundred_bears     0.00900 K - 4477.75x slower</pre><pre>Memory usage statistics:</pre><pre>Name                                            average  deviation         median         99th %<br>noop                                           40.16 KB     ±0.00%       40.16 KB       40.16 KB<br>module_attribute_three_hundred_bears           37.04 KB     ±1.93%       36.88 KB       40.13 KB<br>module_attribute_bears                         37.04 KB     ±1.92%       36.88 KB       40.13 KB<br>Application.get_env_bears                     321.16 KB     ±0.00%      321.16 KB      321.16 KB<br>Application.get_env_three_hundred_bears     19312.34 KB     ±0.00%    19312.34 KB    19312.34 KB</pre><pre>Comparison:<br>noop                                           40.16 KB<br>module_attribute_three_hundred_bears           36.88 KB - 0.92x memory usage<br>module_attribute_bears                         36.88 KB - 0.92x memory usage<br>Application.get_env_bears                     321.16 KB - 8.00x memory usage<br>Application.get_env_three_hundred_bears     19312.34 KB - 480.93x memory usage</pre><p>Thanks to <a href="https://medium.com/u/7fb6e63fd8bd">Richard Duarte</a> for helping me with this post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=475aca10011d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tripping-engineering/blazing-fast-elixir-configuration-475aca10011d">Blazing fast Elixir configuration</a> was originally published in <a href="https://medium.com/tripping-engineering">Tripping Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to implement sliding timeouts in your Elixir GenServers]]></title>
            <link>https://medium.com/tripping-engineering/how-to-implement-sliding-timeouts-in-your-elixir-genservers-cc5a2ed70db9?source=rss-9173227d41e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc5a2ed70db9</guid>
            <category><![CDATA[message]]></category>
            <category><![CDATA[genserver]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[sliding]]></category>
            <category><![CDATA[time-out]]></category>
            <dc:creator><![CDATA[Khaja Minhajuddin]]></dc:creator>
            <pubDate>Tue, 31 Jul 2018 18:01:01 GMT</pubDate>
            <atom:updated>2018-07-31T18:01:01.245Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RljwIvqRxILGbENl" /><figcaption>Photo by <a href="https://unsplash.com/@kentoiemoto?utm_source=medium&amp;utm_medium=referral">Kento Iemoto</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>At Tripping.com, whenever a user makes a search, one of our Elixir microservice spawns up a bunch of GenServers to talk to a few external systems. The data processed through these is sent over websockets to the user’s browser. This part of the code is a bit CPU/memory/network intensive because it needs to keep network connections open, do a lot of JSON serialization/deserialization and store the intermediate data in memory to keep things fast.</p><p>It has been working pretty great. However, keeping all this data in memory and having network connections open for idle users is not a good use of our resources. So, to make our app leaner, we wanted to discard all the searches where users are idle for more than 10 minutes.</p><h4>Timeout a fixed number of seconds after init</h4><p>Getting a timeout which fires in 10 minutes is pretty easy in Elixir. All you do is a send a message to yourself using `Process.send_after`.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04a5dbebda69a5fb01ae70944249ff74/href">https://medium.com/media/04a5dbebda69a5fb01ae70944249ff74/href</a></iframe><p>This will just start a timer when the `GenServer` is initialized and timeout after a fixed number of seconds. However, we wanted a sliding timeout which pushes the timeout further each time the client had some activity.</p><h4>Use Process.cancel_timer</h4><p>This led us to the next possible solution using `Process.cancel_timer`. We changed our code to handle a `:touch` message on the `GenServer` which cancelled the previous timer and created a new one instead.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59fb8fefe08438b770c496b6dd20e855/href">https://medium.com/media/59fb8fefe08438b770c496b6dd20e855/href</a></iframe><p>However, what happens when the timer triggers just before you call `Process.cancel_timer`? The `:idle_timeout` still gets sent and ends up (in this instance) purging all our search data. We went down this rabbit hole a bit further to remedy the situation but ended up with a lot of complex code which we decided to scrap in favor of a simpler solution.</p><h4>Use a new ref for each new idle timeout</h4><p>We found a simpler solution by making a new ref (using `make_ref`) and sending it as part of the `:idle_timeout` message. Whenever we wanted `touch` we just created a new ref and sent it over. The latest ref was also stored into the `GenServer` state so that it could be compared when an `:idle_timeout` came in, to see if it was the latest ref or a ref from an old timer. This turned out to be much simple and without any race conditions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4de414574fe5ec73b9ae880cdaeb8105/href">https://medium.com/media/4de414574fe5ec73b9ae880cdaeb8105/href</a></iframe><p>Thanks to <a href="https://medium.com/u/7fb6e63fd8bd">Richard Duarte</a> for helping me with this blog post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc5a2ed70db9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tripping-engineering/how-to-implement-sliding-timeouts-in-your-elixir-genservers-cc5a2ed70db9">How to implement sliding timeouts in your Elixir GenServers</a> was originally published in <a href="https://medium.com/tripping-engineering">Tripping Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use private hex dependencies in your docker images]]></title>
            <link>https://medium.com/tripping-engineering/how-to-use-private-hex-dependencies-in-your-docker-images-42b2d01d8d70?source=rss-9173227d41e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/42b2d01d8d70</guid>
            <category><![CDATA[hex]]></category>
            <category><![CDATA[mix]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Khaja Minhajuddin]]></dc:creator>
            <pubDate>Tue, 10 Jul 2018 17:01:01 GMT</pubDate>
            <atom:updated>2018-07-10T17:01:01.751Z</atom:updated>
            <content:encoded><![CDATA[<p>There’s not much support for elixir deployments out of the box with Jenkins and ECS. We wanted to simplify our setup by moving common code to a repository all our projects could include — but with a containerized solution dealing with private github repos posed unique challenges. Here is how we solved it:</p><h3>1. Creating a hex package</h3><p>This turned out to be very easy. We just created a new mix project, copied the files, renamed the modules, and pushed the code to a GitHub repository.</p><pre>mix new util<br>cd util<br># mv util.ex lib/ # copy the code and rename the modules<br>git add . &amp;&amp; git commit -m “init”<br>hub create tripping/util<br>git push origin master -u<br>git tag — annotate — message v0.1.0 v0.1.0<br>git push origin — tags</pre><h3>2. Adding the dependency to our project</h3><h3>Take 1</h3><p>Hex makes adding dependencies very easy, so all we had to do was add the following line in our deps and run `mix deps.get`</p><pre>def deps do<br>  [<br>    # ...<br>    {:exutils, github: &quot;tripping/exutils.git&quot;, tag: &quot;v0.1.0&quot;},<br>    # ...<br>  ]<br>end</pre><p>However, as it turns out <a href="https://github.com/elixir-lang/elixir/issues/3422">the github option works only for public repos</a></p><h3>Take 2</h3><p>Well, the alternative for including private repos was actually very simple too, we just had to use the full git url.</p><pre>def deps do<br>  [<br>    # ...<br>    {:exutils, git: &quot;<a href="/service/mailto:git@github.com">git@github.com</a>:tripping/exutils.git&quot;, tag: &quot;v0.1.0&quot;},<br>    # ...<br>  ]<br>end</pre><p>This worked great in development, However it failed on deployment.</p><h3>Our hosting setup</h3><p>We use AWS ECS to host our microservices, and each of them is built as a docker image which is then started on an ECS cluster. These images are built on Jenkins and are pushed to AWS ECR from which our ECS clusters pull and spin them up.</p><h3>Our Dockerfile</h3><pre>FROM ${DOCKER_IMAGE}</pre><pre>ENV REFRESHED_AT=2018-03-20 \<br>    # Set this so that CTRL+G works properly<br>    TERM=xterm \<br>    MIX_ENV=${MIX_ENV} \<br>    PORT=${PORT}</pre><pre>RUN apt-get update \<br>  &amp;&amp; update-ca-certificates --fresh \<br>  &amp;&amp; rm -rf /var/lib/apt/lists/* \<br>  &amp;&amp; mix local.hex --force \<br>  &amp;&amp; mix local.rebar --force</pre><pre>COPY . /opt/app</pre><pre>WORKDIR /opt/app</pre><pre>RUN mix deps.get --only &quot;${MIX_ENV}&quot; \<br>  &amp;&amp; mix release</pre><pre>CMD [ &quot;/opt/app/bootstrap.sh&quot; ]</pre><p>Docker image build script</p><pre># ....<br>docker build \<br>  --file &quot;$DOCKERFILE&quot; \<br>  --tag &quot;${IMAGE_URL}:${IMAGE_VERSION_TAG}&quot; \<br>  &quot;$ROOT_DIR&quot;</pre><pre>docker push &quot;${IMAGE_URL}:${IMAGE_VERSION_TAG}&quot;<br># ....</pre><p>So, as you can see, we generate an erlang release inside a docker image, as part of the image creation process. Once we build a new image, we just update the task definition to use it.</p><p>Well that was a long digression, But the problem with this setup is that since `mix deps.get` runs from inside a docker build process (while the image is being built) <a href="https://github.com/moby/moby/issues/6396">there is no way to forward our ssh-agent to authenticate with GitHub</a>.</p><h3>Take 3</h3><p>The final solution actually turned out to be simpler than we anticipated (Kudos to the Elixir team for thinking through every possibility). We ended up adding this dependency as a git submodule and using the `path` option in deps.</p><pre>git submodule add <a href="/service/mailto:git@github.com">git@github.com</a>:tripping/exutils.git private_deps/exutils<br>git submodule update — init — recursive</pre><pre>def deps do<br>  [<br>    # ...<br>    {:exutils, path: &quot;./private_deps/exutils/&quot;},<br>    # ...<br>  ]<br>end</pre><p>Now our jenkins server just updates the submodules before running our build and all our private deps are in place to be built inside docker.</p><p>Thanks to <a href="https://medium.com/u/7fb6e63fd8bd">Richard Duarte</a> for helping me with this blog post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42b2d01d8d70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tripping-engineering/how-to-use-private-hex-dependencies-in-your-docker-images-42b2d01d8d70">How to use private hex dependencies in your docker images</a> was originally published in <a href="https://medium.com/tripping-engineering">Tripping Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to architect your services to use AWS ECS using Spot Instances]]></title>
            <link>https://medium.com/staticgarden/how-to-architect-your-services-to-use-aws-ecs-using-spot-instances-59823473a714?source=rss-9173227d41e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/59823473a714</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ec]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[sqs]]></category>
            <dc:creator><![CDATA[Khaja Minhajuddin]]></dc:creator>
            <pubDate>Sun, 17 Jun 2018 10:22:01 GMT</pubDate>
            <atom:updated>2018-06-17T10:25:32.201Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KIlb3WMimN90vNvQ" /><figcaption>“Macro of sound equipment mixing board with equalizers, knobs, and buttons” by <a href="https://unsplash.com/@chuttersnap?utm_source=medium&amp;utm_medium=referral">chuttersnap</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Alright, I’ve a bunch of side projects which make decent money. However, till recently I’ve been setting up products using a virtual server (on AWS or DO or Linode) and by creating one user account per service all sitting behind an Nginx reverse proxy. This has been working fine most of the time, However this kind of setup is a bit time consuming and you are screwed if your server goes boom! I’ve been researching a few deployment strategies and different architectures to build a few of my new services. I think I’ve found the right combination using AWS Lambda, SQS, DynamoDB and ECS using a cluster of spot instances.</p><p>Most of you may know that AWS allows you to use spot instances which are instances available at a highly reduced price ranging from 10% to 30% of the original cost. If this seems too good to be true there is of course a catch: Spot instances can be terminated any time. There is a notification service which allows you to be notified of these terminations 2 minutes in advance (which is not enough for a typical service). So, how do we use spot instances without bringing down our services? We don’t want our services to go down when our spot instances are terminated!</p><p>To use spot instances we need to use a different architecture, The way that I<br>am designing my services is in the following</p><pre>Static site hosted on S3 and distributed by cloudfront</pre><pre>AWS Lambda<br>(this handles the form endpoints for the dynamic stuff)<br>My lambdas usually push events to an SQS queue so that they are fast</pre><pre>ECS Cluster (using Spot instances)<br>Now this cluster hosts the core of the service, which picks up things from our<br>SQS queue and processes them. If a spot instance goes down AWS will bring another<br>back in a different availability zone (if the price of this type of instance is<br>lower in that availability zone). And if a task is not completed our new Spot<br>instance will pick up tasks from our queue and starts processing them.</pre><p>So, to explain the above a little more, the frontend comprises of a static site and AWS Lambda which are always on all the time and whenever a user does something the action gets saved in an SQS queue via a Lambda. Once this is done our ECS cluster (which uses spot instance) takes over and finishes the job. This removes the need for your worker instances to be on all the time, they can now be terminated with gay abandon without impacting your core service.</p><p>I’ll do a more detailed post using the example of our new HTTP to Email service.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59823473a714" width="1" height="1" alt=""><hr><p><a href="https://medium.com/staticgarden/how-to-architect-your-services-to-use-aws-ecs-using-spot-instances-59823473a714">How to architect your services to use AWS ECS using Spot Instances</a> was originally published in <a href="https://medium.com/staticgarden">StaticGarden</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bring your variables back from the dead!]]></title>
            <link>https://medium.com/tripping-engineering/bring-your-variables-back-from-the-dead-ea250cf58ba4?source=rss-9173227d41e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea250cf58ba4</guid>
            <category><![CDATA[meta]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Khaja Minhajuddin]]></dc:creator>
            <pubDate>Tue, 12 Jun 2018 18:01:01 GMT</pubDate>
            <atom:updated>2018-06-12T18:01:01.191Z</atom:updated>
            <content:encoded><![CDATA[<p>We use a lot of Elixir at <a href="http://www.tripping.com/">Tripping</a><strong>®</strong>, and using iex is a great way to explore the standard library and hex packages. However, there are times when we have to restart iex sessions. And, it is always a pain to get our variables in the right state after restarting iex, if you’ve felt the same, there’s good news for you :)</p><p>We’ve created a small package which alleviates some of this pain by allowing you to persist your variables when you close your iex session and resurrecting them when you open a new one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*kcqzMsig4GjbA9jUJ4NI9Q.png" /><figcaption>Zombie Demo</figcaption></figure><p>Checkout the project at <a href="https://github.com/tripping/zombie">https://github.com/tripping/zombie</a></p><p>Let’s dive into the code base and see how this works. Elixir has awesome meta programming capabilities and all this can be done in less than 50 LOC.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4d17e89f2f8e2797507760c50a1824f/href">https://medium.com/media/c4d17e89f2f8e2797507760c50a1824f/href</a></iframe><p>There are 2 main macros in this file:</p><p>First is the Zombie.bury which stores the variables available in the current scope in a file named .iex_state , Elixir provides an easy way to get a hold of all the variables in the current scope using a macro called <a href="https://hexdocs.pm/elixir/Kernel.html#binding/1">binding</a> which returns a keyword list of variable names and their values. Now, we take this and use the <a href="http://erlang.org/doc/man/erlang.html#term_to_binary-1">:erlang.term_to_binary</a> function to convert the whole expression into a binary which can then be saved to a file.</p><p>And the second macro is named Zombie.resurrect which reads a previously stored state file and passes it through :erlang.binary_to_term to deserialize the data from our file into Erlang/Elixir terms. Once we have these terms, it is just a matter of looping over the variable property list and creating a function for each (which returns the associated value) and finally wrapping it in a module named Zombie.Vars</p><p>That was all that was needed resurrect dead variables 😁 I’d love to see other folks do this for projects which use ruby, javascript etc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea250cf58ba4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tripping-engineering/bring-your-variables-back-from-the-dead-ea250cf58ba4">Bring your variables back from the dead!</a> was originally published in <a href="https://medium.com/tripping-engineering">Tripping Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to securely compare passwords in Elixir]]></title>
            <link>https://medium.com/@minhajuddin/how-to-securely-compare-passwords-in-elixir-afaf186bb4a9?source=rss-9173227d41e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/afaf186bb4a9</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[passwords]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[web-applications]]></category>
            <dc:creator><![CDATA[Khaja Minhajuddin]]></dc:creator>
            <pubDate>Sat, 28 Apr 2018 14:43:43 GMT</pubDate>
            <atom:updated>2018-04-28T14:43:43.866Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are building an authentication system. You need to avoid using a simple string equality match for checking passwords. If you do this, you open yourself to <a href="https://en.wikipedia.org/wiki/Timing_attack">timing attacks</a>. You can build a secure compare utility in Elixir (like I did in my ignorance) or use <a href="https://hexdocs.pm/plug/Plug.Crypto.html#secure_compare/2">Plug.Crypto.secure_compare</a>, you probably already have a dependency on plug if you are building a web application in Elixir.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afaf186bb4a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>