<?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 DAR on Medium]]></title>
        <description><![CDATA[Stories by DAR on Medium]]></description>
        <link>https://medium.com/@darnahsan?source=rss-388bbad296da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_ALGOEZgnhOWLfSV.jpg</url>
            <title>Stories by DAR on Medium</title>
            <link>https://medium.com/@darnahsan?source=rss-388bbad296da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 02:31:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@darnahsan/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[Building a Scalable Audit Logging Pipeline in Elixir: Handling Millions of Events Without Breaking…]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://darnahsan.medium.com/building-a-scalable-audit-logging-pipeline-in-elixir-handling-millions-of-events-without-breaking-821a05a330b1?source=rss-388bbad296da------2"><img src="https://cdn-images-1.medium.com/max/1000/0*RgA5l6qfrEBAI3FA.png" width="1000"></a></p><p class="medium-feed-snippet">In enterprise applications dealing with payroll, compensation, and benefits data, every change matters. When a single data point can&#x2026;</p><p class="medium-feed-link"><a href="https://darnahsan.medium.com/building-a-scalable-audit-logging-pipeline-in-elixir-handling-millions-of-events-without-breaking-821a05a330b1?source=rss-388bbad296da------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://darnahsan.medium.com/building-a-scalable-audit-logging-pipeline-in-elixir-handling-millions-of-events-without-breaking-821a05a330b1?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/821a05a330b1</guid>
            <category><![CDATA[outbox]]></category>
            <category><![CDATA[cdc]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Mon, 29 Dec 2025 11:44:41 GMT</pubDate>
            <atom:updated>2025-12-29T11:46:15.667Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building Resilient Event-Driven Systems: Lessons from the Distributed Trenches]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://darnahsan.medium.com/building-resilient-event-driven-systems-lessons-from-the-distributed-trenches-825327c1a386?source=rss-388bbad296da------2"><img src="https://cdn-images-1.medium.com/max/1000/0*spz9h4G5P6tYV6lH.png" width="1000"></a></p><p class="medium-feed-snippet">When you first look at a distributed architecture diagram with services scattered across multiple cloud providers, regions, and continents&#x2026;</p><p class="medium-feed-link"><a href="https://darnahsan.medium.com/building-resilient-event-driven-systems-lessons-from-the-distributed-trenches-825327c1a386?source=rss-388bbad296da------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://darnahsan.medium.com/building-resilient-event-driven-systems-lessons-from-the-distributed-trenches-825327c1a386?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/825327c1a386</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Tue, 04 Nov 2025 07:50:31 GMT</pubDate>
            <atom:updated>2025-11-04T07:54:44.428Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Bridging the AI Gap: Simplifying LLM Development in Elixir with langchain]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/elemental-elixir/bridging-the-ai-gap-simplifying-llm-development-in-elixir-with-langchain-ex-fa1efc4bbe9d?source=rss-388bbad296da------2"><img src="https://cdn-images-1.medium.com/max/1024/1*H9j1661uTlXXY_ARn2Wunw.png" width="1024"></a></p><p class="medium-feed-snippet">Friend&#x2019;s link for non-members</p><p class="medium-feed-link"><a href="https://medium.com/elemental-elixir/bridging-the-ai-gap-simplifying-llm-development-in-elixir-with-langchain-ex-fa1efc4bbe9d?source=rss-388bbad296da------2">Continue reading on Elemental Elixir »</a></p></div>]]></description>
            <link>https://medium.com/elemental-elixir/bridging-the-ai-gap-simplifying-llm-development-in-elixir-with-langchain-ex-fa1efc4bbe9d?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa1efc4bbe9d</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[inference]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[langchain]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Thu, 01 May 2025 16:17:06 GMT</pubDate>
            <atom:updated>2025-05-06T04:49:50.945Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Overcoming Challenges with Google Vertex API, s6-overlay, and Fly.io:]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://blog.devops.dev/overcoming-challenges-with-google-vertex-api-s6-overlay-and-fly-io-64a8f89e33ff?source=rss-388bbad296da------2"><img src="https://cdn-images-1.medium.com/max/1000/0*N6TnC_sZ_4D06IbC.png" width="1000"></a></p><p class="medium-feed-snippet">When working with Google Vertex AI&#x2019;s API, one of the challenges developers face is its reliance on access tokens that are valid for only&#x2026;</p><p class="medium-feed-link"><a href="https://blog.devops.dev/overcoming-challenges-with-google-vertex-api-s6-overlay-and-fly-io-64a8f89e33ff?source=rss-388bbad296da------2">Continue reading on DevOps.dev »</a></p></div>]]></description>
            <link>https://blog.devops.dev/overcoming-challenges-with-google-vertex-api-s6-overlay-and-fly-io-64a8f89e33ff?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/64a8f89e33ff</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[aiops]]></category>
            <category><![CDATA[google-cloud]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Sun, 02 Feb 2025 16:37:37 GMT</pubDate>
            <atom:updated>2025-02-04T18:07:23.732Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Leveraging GenServer and Queueing Techniques: Handling API Rate Limits to AI Inference services]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/elemental-elixir/leveraging-genserver-and-queueing-techniques-handling-api-rate-limits-to-ai-inference-services-db6a2a8b4755?source=rss-388bbad296da------2"><img src="https://cdn-images-1.medium.com/max/1000/0*2yhTtkvkxr7TFl3D.jpeg" width="1000"></a></p><p class="medium-feed-snippet">In the realm of efficient application development, managing external service rate limits is a pivotal challenge. Recently faced this task&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/elemental-elixir/leveraging-genserver-and-queueing-techniques-handling-api-rate-limits-to-ai-inference-services-db6a2a8b4755?source=rss-388bbad296da------2">Continue reading on Elemental Elixir »</a></p></div>]]></description>
            <link>https://medium.com/elemental-elixir/leveraging-genserver-and-queueing-techniques-handling-api-rate-limits-to-ai-inference-services-db6a2a8b4755?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/db6a2a8b4755</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Sat, 02 Nov 2024 08:38:41 GMT</pubDate>
            <atom:updated>2024-11-12T19:26:07.425Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Pooling AMQP TLS connections in Elixir for high throughput and low latency]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/elemental-elixir/pooling-amqp-tls-connections-in-elixir-for-high-throughput-and-low-latency-f90dc5fffa1e?source=rss-388bbad296da------2"><img src="https://cdn-images-1.medium.com/max/1000/0*rwEcfPZOCwv4jbs6.png" width="1000"></a></p><p class="medium-feed-snippet">In the fast-paced, data-driven world of computing, reliable message brokers are critical for communication between services. One of the&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/elemental-elixir/pooling-amqp-tls-connections-in-elixir-for-high-throughput-and-low-latency-f90dc5fffa1e?source=rss-388bbad296da------2">Continue reading on Elemental Elixir »</a></p></div>]]></description>
            <link>https://medium.com/elemental-elixir/pooling-amqp-tls-connections-in-elixir-for-high-throughput-and-low-latency-f90dc5fffa1e?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/f90dc5fffa1e</guid>
            <category><![CDATA[event-driven]]></category>
            <category><![CDATA[pooling]]></category>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[amqp]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Sun, 15 Sep 2024 03:33:34 GMT</pubDate>
            <atom:updated>2024-11-05T05:12:05.482Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Simplifying Webhook Handling with Vector.dev: A Modern Solution for Serverless Apps]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://blog.devops.dev/simplifying-webhook-handling-with-vector-dev-a-modern-solution-for-serverless-apps-83f203fe6541?source=rss-388bbad296da------2"><img src="https://cdn-images-1.medium.com/max/1000/0*0ht45OB7jXg53Ho9.jpeg" width="1000"></a></p><p class="medium-feed-snippet">Simplifying Webhook Handling with Vector.dev: A Modern Solution for Serverless Apps
&#xA0;In the world of serverless applications and&#x2026;</p><p class="medium-feed-link"><a href="https://blog.devops.dev/simplifying-webhook-handling-with-vector-dev-a-modern-solution-for-serverless-apps-83f203fe6541?source=rss-388bbad296da------2">Continue reading on DevOps.dev »</a></p></div>]]></description>
            <link>https://blog.devops.dev/simplifying-webhook-handling-with-vector-dev-a-modern-solution-for-serverless-apps-83f203fe6541?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/83f203fe6541</guid>
            <category><![CDATA[webhooks]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[vector]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Thu, 05 Sep 2024 15:01:53 GMT</pubDate>
            <atom:updated>2024-09-05T17:17:08.551Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Multi-Layered Caching with Decorators in Elixir: Optimizing Performance and Scalability]]></title>
            <link>https://medium.com/elemental-elixir/multi-layered-caching-with-decorators-in-elixir-optimizing-performance-and-scalability-51d562faa02e?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/51d562faa02e</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Tue, 18 Jun 2024 07:30:24 GMT</pubDate>
            <atom:updated>2024-06-18T14:02:48.856Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Y1TE-UO2fGUhvx-WaugQg.jpeg" /></figure><p>Phil Karlton’s famous quote aptly captures the essence of caching in computer science: “There are only two hard things in Computer Science: cache invalidation and naming things.” Caching is a powerful technique to improve application performance by storing frequently accessed data in a faster, more readily accessible location. However, effective cache invalidation remains a challenge.</p><p>Caching is a difficult problem and invalidating a cache is even more difficult. Elixir, with its powerful in-memory caching options such as ETS and DETS, provides a robust solution that often eliminates the need for external caching systems like Memcached or Redis. For a deep dive, <a href="https://blog.appsignal.com/2019/11/12/caching-with-elixir-and-ets.html">Dashbit’s blog post</a> on why you may not need Redis with Elixir is an excellent resource. But for globally distributed, dynamically scaling serverless environments, these in-memory caches become less suitable.</p><p>However, scaling caching across multiple global regions in a serverless environment introduces new challenges. Dynamic scaling of nodes means that your in-memory cache can disappear along with the node, complicating matters.</p><p>Cachex, the most popular Elixir caching library, offers a clustered cache option but lacks support for dynamic node configuration. This limitation becomes evident in environments like Fly.io, where nodes scale dynamically and their addresses aren’t known at startup. Engaging with the Fly.io community led me to an <a href="https://github.com/whitfin/cachex/issues/246">open issue</a> on Cachex’s GitHub regarding dynamic node configuration. This search introduced me to <a href="https://github.com/cabol/nebulex">Nebulex</a>, a feature-rich library supporting multiple cache stores, including Cachex and Redis.</p><p>Nebulex also supports various caching patterns out of the box. While setting up the Redis adapter for Nebulex, I encountered a blocker <a href="https://github.com/cabol/nebulex_redis_adapter/issues/44">issue</a> with Upstash Redis, revealing another limitation. Despite this, the exploration provided insights on constructing a layered caching solution using decorators a approach Nebulex uses.</p><p>With the limitations of Cachex in dynamic environments and the Redis adapter for Nebulex not meeting expectations, Inspired by the strengths of Cachex and Nebulex, we can create a custom layered caching solution using decorators in Elixir. This approach combines the speed of a local Cachex as L1 (short TTL) with the scalability of an external Redis as L2 (longer TTL)), reducing code clutter and improving maintainability. This setup avoids cluttering the code with numerous get, set, and delete operations by using decorators.</p><p>Advantages of Multi-Layered Caching</p><ul><li>Faster Responses: Cachex (L1) provides microsecond latency for frequently accessed data.</li><li>Reduced External Hits: Redis (L2) serves as a fallback, significantly reducing the number of requests to external services.</li><li>Cost Efficiency: Fewer requests to Redis minimize cloud costs.</li><li>Graceful Degradation: The system can serve stale data from L1 within a threshold, ensuring continuity while fetching fresh data from L2.</li></ul><p>Here’s an outline of the approach:</p><ul><li>Define the Decorator: Create a decorator function that accepts the actual function to be wrapped and the cache configuration options (e.g., cache type, TTLs for L1 and L2).</li><li>Check L1 Cache: Inside the decorator, first check the L1 cache (Cachex) for the requested data using the key derived from the function arguments.</li><li>Retrieve from L2 Cache: If the data is not found in L1, retrieve it from the L2 cache (Redis) using the same key.</li><li>Fetch from Source: If both L1 and L2 caches miss, call the wrapped function to fetch the data from the original source.</li><li>Cache the Result: Store the fetched data in both L1 and L2 caches with their respective TTLs.</li><li>Return the Data: Finally, return the retrieved or fetched data.</li><li>By wrapping functions with this decorator, you can transparently introduce caching without altering the core logic of your application.</li></ul><p>Using Elixir’s <a href="https://github.com/arjan/decorator">decorator</a> library it’s as simple as writing it as such</p><p>Decorator allowing you to decorate your functions as <br>@decorate lx_fetch([&quot;key&quot;, args0])<br>@decorate lx_evict([&quot;key&quot;, args0])</p><pre>defmodule Maverick.Cache.Decorator do<br>  @moduledoc &quot;&quot;&quot;<br>  Maverick.Cache.Decorator<br>  &quot;&quot;&quot;<br><br>  use Decorator.Define, lx_fetch: 1, lx_evict: 1<br><br>  alias Maverick.Cache.L1, as: CacheL1<br>  alias Maverick.Cache.L2, as: CacheL2<br><br>  def lx_fetch(attrs, body, _context) do<br>    quote do<br>      case CacheL1.get(unquote(attrs)) do<br>        {:ok, nil} -&gt;<br>          case CacheL2.get(unquote(attrs)) do<br>            {:ok, nil} -&gt;<br>              unquote(body)<br><br>            {:ok, data} -&gt;<br>              CacheL1.set(unquote(attrs), data)<br>              data<br><br>            {:error, _reason} -&gt;<br>              unquote(body)<br>          end<br><br>        {:ok, data} -&gt;<br>          data<br><br>        {:error, _reason} -&gt;<br>          unquote(body)<br>      end<br>    end<br>  end<br><br>  def lx_evict(attrs, body, _context) do<br>    quote do<br>      CacheL1.del(unquote(attrs))<br>      CacheL2.del(unquote(attrs))<br>      unquote(body)<br>    end<br>  end<br>end</pre><p>L1 Cache</p><pre>defmodule Maverick.Cache.L1 do<br>  @moduledoc &quot;&quot;&quot;<br>  Maverick.Cache.L1<br>  &quot;&quot;&quot;<br>  require Logger<br><br>  use Appsignal.Instrumentation.Decorators<br><br>  alias Maverick.Utility.Helper<br><br>  @cachex :maverick_cachex<br>  @ttl 1800<br><br>  @decorate transaction_event()<br>  def get(key) do<br>    cache_key = Helper.generate_cache_key(key)<br>    Logger.info(&quot;Get from L1 Cache for #{cache_key}&quot;)<br>    Cachex.get(@cachex, cache_key)<br>  end<br><br>  @decorate transaction_event()<br>  def set(key, value, ttl \\ @ttl) do<br>    cache_key = Helper.generate_cache_key(key)<br>    Logger.info(&quot;Set in L1 Cache for #{cache_key}&quot;)<br>    Cachex.put(@cachex, cache_key, value, ttl: :timer.seconds(ttl))<br>  end<br><br>  @decorate transaction_event()<br>  def del(key) do<br>    cache_key = Helper.generate_cache_key(key)<br>    Logger.info(&quot;Delete from L1 Cache for #{cache_key}&quot;)<br>    Cachex.del(@cachex, cache_key)<br>  end<br>end</pre><p>L2 Cache</p><pre>defmodule Maverick.Cache.L2 do<br>  @moduledoc &quot;&quot;&quot;<br>  Maverick.Cache.L2<br>  &quot;&quot;&quot;<br>  require Logger<br><br>  use Appsignal.Instrumentation.Decorators<br><br>  alias Maverick.Utility.Helper<br><br>  @redis :maverick_redix<br>  @ttl 7_776_000<br><br>  @decorate transaction_event()<br>  def get(key) do<br>    cache_key = Helper.generate_cache_key(key)<br><br>    Logger.info(&quot;Get from L2 Cache for #{cache_key}&quot;)<br><br>    case Redix.command(@redis, [&quot;GET&quot;, cache_key]) do<br>      {:ok, nil} -&gt; {:ok, nil}<br>      {:ok, data} -&gt; {:ok, :erlang.binary_to_term(data)}<br>      {:error, reason} -&gt; {:error, reason}<br>    end<br>  end<br><br>  @decorate transaction_event()<br>  def set(key, value, ttl \\ @ttl) do<br>    cache_key = Helper.generate_cache_key(key)<br>    Logger.info(&quot;Set in L2 Cache for #{cache_key}&quot;)<br>    Redix.command(@redis, [&quot;SET&quot;, cache_key, :erlang.term_to_binary(value), &quot;EX&quot;, ttl])<br>  end<br><br>  @decorate transaction_event()<br>  def del(key) do<br>    cache_key = Helper.generate_cache_key(key)<br>    Logger.info(&quot;Delete from L2 Cache for #{cache_key}&quot;)<br>    Redix.command(@redis, [&quot;DEL&quot;, cache_key])<br>  end<br><br>  def flush_all() do<br>    Redix.command(:redix, [&quot;FLUSHALL&quot;])<br>    |&gt; case do<br>      {:ok, status} -&gt; status<br>      {:error, reason} -&gt; reason<br>    end<br>  end<br>end</pre><p>Cache key generation is done as in Nebulex using erlang&#39;s phash/2</p><pre>def generate_cache_key(key) do<br>    :erlang.phash2(key) |&gt; Integer.to_string()<br>end</pre><p>And my favourite version of Phil Karlton’s quote is:</p><p>“There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors.”<br> — Leon Bambrick</p><p><em>Originally published at </em><a href="https://dev.to/darnahsan/multi-layered-caching-with-decorators-in-elixir-optimizing-performance-and-scalability-3gd7"><em>https://dev.to</em></a><em> on June 18, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51d562faa02e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elemental-elixir/multi-layered-caching-with-decorators-in-elixir-optimizing-performance-and-scalability-51d562faa02e">Multi-Layered Caching with Decorators in Elixir: Optimizing Performance and Scalability</a> was originally published in <a href="https://medium.com/elemental-elixir">Elemental Elixir</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brod; boss kafka in elixir]]></title>
            <link>https://medium.com/elemental-elixir/brod-boss-kafka-in-elixir-2deeb21e44f2?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/2deeb21e44f2</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Mon, 03 Jun 2024 15:33:03 GMT</pubDate>
            <atom:updated>2024-06-03T15:35:41.397Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*3LHAkz3_jt4YKbcw.png" /></figure><p>Elixir has rapidly gained recognition as a powerful language for developing distributed systems. Its concurrency model, based on the Erlang VM (BEAM), allows developers to build highly scalable and fault-tolerant applications. One of the areas where Elixir shines is in reading messages from Kafka using Broadway to build concurrent and multi-stage data ingestion and processing pipelines. However, when it comes to producing messages to Kafka, Elixir’s ecosystem seems to lack a unified focus, leading to some confusion.</p><p>Elixir’s inherent support for concurrency and fault tolerance makes it an ideal choice for distributed systems. The language’s lightweight process model, along with features like supervisors and the actor model, enables developers to create systems that can handle massive loads and recover gracefully from failures. This makes Elixir particularly well-suited for distributed systems, where reliability and performance are crucial.</p><p>In the Elixir ecosystem, there is a clear focus on consuming messages from Kafka. Libraries like Broadway make it easy to build sophisticated data ingestion pipelines. Broadway allows developers to define multi-stage pipelines that can process large volumes of data concurrently, leveraging Elixir’s strengths in concurrency and fault tolerance.</p><p>While Broadway excels at consuming messages, there’s a slight terminology hiccup. The method for sending messages is called produce, which might be a bit confusing. It’s important to remember that Broadway focuses on the consumer side of the Kafka equation.</p><p>However, when it comes to producing messages to Kafka, Elixir’s libraries present a more fragmented landscape.</p><p>There are three primary Kafka libraries available for Elixir developers: brod, kaffe, and kafka_ex. Each of these libraries has its own strengths and use cases.</p><p>brod: An Erlang client for Kafka, brod is known for its robustness and performance. It operates seamlessly within the BEAM ecosystem, taking advantage of Erlang’s mature infrastructure for building distributed systems. However, working with brod can be cumbersome and requires a fair amount of setup. Despite this, it remains a reliable and performant choice for Kafka integration.</p><p>kaffe: A wrapper around brod, kaffe simplifies the process of interacting with Kafka, particularly for those using Heroku Kafka clusters. By abstracting away some of the complexities of brod, kaffe makes it easier for developers to get started with Kafka in Elixir. It focuses on providing a more user-friendly experience while still leveraging the underlying power of brod.</p><p>kafka_ex: Currently in a state of transition, kafka_ex is undergoing significant changes that are not backward compatible. This situation can be likened to Python’s shift from version 2 to version 3, where developers faced considerable breaking changes. While kafka_ex has been a popular choice, the ongoing transition means developers need to be cautious about using it in production until the changes stabilize.</p><p>Keeping in mind all the above and scouring elixirforum.com the most shared opinion was to go with brod and write a wrapper around it.</p><p>Something that lacks is over how to set it up in elixir and in particular phoenix as brod is an erlang library.</p><p>To setup brod in phoenix you need to define a supervisor process that can than be added to your phoenix supervisor like other process to be part of your supervision tree.</p><p>To setup the brod client with sasl and ssl as a supervisor it can be done as below.</p><pre>defmodule Maverick.Kafka.BrodSupervisor do<br>  @moduledoc &quot;&quot;&quot;<br>  Maverick.Kafka.BrodSupervisor<br>  &quot;&quot;&quot;<br>  use Supervisor<br><br>  alias Maverick.Kafka, as: Kafka<br><br>  def start_link(_config) do<br>    Supervisor.start_link(__MODULE__, [], name: __MODULE__)<br>  end<br><br>  def init(_config) do<br>    :ok =<br>      :brod.start_client(<br>        Kafka.hosts(),<br>        Kafka.brod_client(),<br>        ssl: true,<br>        ssl_options: [<br>          # from CAStore package<br>          cacertfile: CAStore.file_path(),<br>          verify_type: :verify_peer,<br>          customize_hostname_check: [<br>            match_fun: :public_key.pkix_verify_hostname_match_fun(:https)<br>          ]<br>        ],<br>        sasl: Kafka.authentication(),<br>        auto_start_producers: true,<br>        reconnect_cool_down_seconds: 10,<br>        default_producer_config: [<br>          required_acks: -1,<br>          partition_buffer_limit: 1024<br>        ]<br>      )<br><br>    children = []<br>    Supervisor.init(children, strategy: :one_for_one)<br>  end<br>end</pre><p>After this you can wrap the message producer for convenience</p><pre>defmodule Maverick.Kafka.Brod do<br>  @moduledoc &quot;&quot;&quot;<br>  Maverick.Kafka.Brod<br>  &quot;&quot;&quot;<br><br>  use Retry.Annotation<br><br>  @retry with: exponential_backoff() |&gt; randomize() |&gt; expiry(10_000)<br>  def produce(client, topic, partition, key, msg) do<br>    :brod.produce_sync(client, topic, partition, key, msg)<br>  end<br>end</pre><p>I highly recommend to check out retry hex package it will save you from all those network issues as network is always dubious.</p><p>Before I close this post the thing I would like to highlight is the required_acks settings and what it means the required_acks (also known as acks) setting determines how many acknowledgements the producer requires the leader to have received before considering a request complete. This setting has a significant impact on the durability and consistency guarantees of your messages. The required_acks can be set to different values:</p><p>0: The producer does not wait for any acknowledgement from the server at all. This means that the producer will not receive any acknowledgement for the messages sent, and message loss can occur if the server fails before the message is written to disk.<br> 1: The leader writes the record to its local log but responds without waiting for full acknowledgement from all followers. This means that the message is acknowledged as soon as the leader writes it, but before all replicas have received it.<br> -1 (or all): The leader waits for the full set of in-sync replicas to acknowledge the record. This is the strongest guarantee and means that the message is considered committed only when all in-sync replicas have acknowledged it.</p><p>In the context of the brod library, setting required_acks: -1 ensures that:</p><p>The producer waits for acknowledgements from all in-sync replicas before considering the message successfully sent.<br> This provides the highest level of durability since the message will be available even if the leader broker fails after the message is acknowledged.</p><p>I hope this makes it simple for people looking to work with Kafka using Elixir.</p><p><em>Originally published at </em><a href="https://dev.to/darnahsan/brod-boss-kafka-in-elixir-eo"><em>https://dev.to</em></a><em> on June 3, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2deeb21e44f2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elemental-elixir/brod-boss-kafka-in-elixir-2deeb21e44f2">Brod; boss kafka in elixir</a> was originally published in <a href="https://medium.com/elemental-elixir">Elemental Elixir</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Ollama with s6-overlay to serve and pull in one shot]]></title>
            <link>https://blog.devops.dev/deploy-ollama-with-s6-overlay-to-serve-and-pull-in-one-shot-5572ed76ea0c?source=rss-388bbad296da------2</link>
            <guid isPermaLink="false">https://medium.com/p/5572ed76ea0c</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[s6-overlay]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ollama]]></category>
            <dc:creator><![CDATA[DAR]]></dc:creator>
            <pubDate>Wed, 29 May 2024 17:27:53 GMT</pubDate>
            <atom:updated>2024-10-04T16:27:25.518Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*7yPOXCBlJtl8Ub4c.png" /></figure><p>Ollama brings the power of Large Language Models (LLMs) directly to your local machine. It removes the complexity of cloud-based solutions by offering a user-friendly framework for running these powerful models.</p><p>Ollama is a robust platform designed to simplify the process of running machine learning models locally. It offers an intuitive interface that allows users to efficiently manage and deploy models without the need for extensive technical knowledge. By streamlining the setup and execution processes, Ollama makes it accessible for developers to harness the power of advanced models directly on their local machines, promoting ease of use and faster iterations in development cycles.</p><p>However, Ollama does come with a notable limitation when it comes to containerized deployments. To download and manage models, Ollama must be actively running and serving before the models can be accessed. This requirement complicates the deployment process within containers, as it necessitates additional steps to ensure the service is up and operational before any model interactions can occur. Consequently, this adds complexity to Continuous Integration (CI) and Continuous Deployment (CD) pipelines, potentially hindering seamless automation and scaling efforts.</p><p>On <a href="https://hub.docker.com/r/ollama/ollama">Ollama’s docker hub</a> it has clear instructions over how to run Ollama requiring 2 steps. In the 1st step you need to have Ollama running before you can download the model to have it ready for prompting.</p><blockquote><em>docker run -d — gpus=all -v ollama:/root/.ollama -p 11434:11434 — name ollama ollama/ollama</em></blockquote><blockquote><em>docker exec -it ollama ollama run llama3</em></blockquote><p>On their Discord there is a help query about how to do this in one shot with a solution which is good but not something I would put in production to lack of orchestration and supervision of processes. Its on github as <a href="https://github.com/spara/autollama">autollama</a> and I recommend to check it out to learn some new tricks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XI7sVB3tNPLlttULfDRQpw.png" /></figure><p>This is where I leveraged my past experience of using <a href="https://github.com/just-containers/s6-overlay">s6-overlay</a> to setup serve and pull in a single container with serve as a longrun and pull as a oneshot dependent on serve to be up and running.</p><p>The directory structure for it as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pkkEM-2GwS6PXMh3sRPTBA.png" /></figure><p>It runs flawlessly with pull running well supervised and orchestrated for it to complete and even when the download gets hammered due to internet speeds it keeps the process going without a glitch.</p><p>Currently there is a known <a href="https://github.com/just-containers/s6-overlay/issues/577">issue in s6-overlay</a> for service wait time which initially caused the oneshot to timeout. Had to <strong>S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 </strong>to disable it for the model download to not fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VBsEdYVqtJPGTrRKIo-qrQ.png" /></figure><p>It is alive, at this point I was just super happy how smoothly it came up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WC-zymCheAi011ql1l-_cg.png" /></figure><p>On following run pull only gets the diff if any without the need to download the whole model again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gI_IsQYZwNp0tCYF0zO_Ig.png" /></figure><p>And Ollama has an api that you can prompt and its a charm to play around with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FUTF49YisPf0_ngGopyUTQ.png" /></figure><p>With serve and pull in a single container to be served along your application it simplifies not only your deployments but also your CI to test it without overly complicating things by hacking scripts.</p><p>I have put the repo on github as <a href="https://github.com/ahsandar/ollama-s6/tree/main">ollama-s6</a> for anyone looking to productionize their ollama deplyoments.</p><p><em>Originally published at </em><a href="https://dev.to/darnahsan/deploy-ollama-with-s6-overlay-to-serve-and-pull-in-one-shot-31cm"><em>https://dev.to</em></a><em> on May 29, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5572ed76ea0c" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/deploy-ollama-with-s6-overlay-to-serve-and-pull-in-one-shot-5572ed76ea0c">Deploy Ollama with s6-overlay to serve and pull in one shot</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>