<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sven Arndt</title>
    <description>The latest articles on DEV Community by Sven Arndt (@tracetics).</description>
    <link>https://dev.to/tracetics</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3848063%2F44100c2b-f7b9-4c30-a248-f3a9d42014f6.png</url>
      <title>DEV Community: Sven Arndt</title>
      <link>https://dev.to/tracetics</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tracetics"/>
    <language>en</language>
    <item>
      <title>How I Built a Funnel Analytics Engine with Laravel Horizon, Redis and a Dead-Simple REST API</title>
      <dc:creator>Sven Arndt</dc:creator>
      <pubDate>Sat, 28 Mar 2026 18:35:44 +0000</pubDate>
      <link>https://dev.to/tracetics/how-i-built-a-funnel-analytics-engine-with-laravel-horizon-redis-and-a-dead-simple-rest-api-5gcn</link>
      <guid>https://dev.to/tracetics/how-i-built-a-funnel-analytics-engine-with-laravel-horizon-redis-and-a-dead-simple-rest-api-5gcn</guid>
      <description>&lt;p&gt;Most analytics tools fall into one of two traps: they're either too shallow to be useful, or so complex that integration alone takes a sprint. I got tired of both. So I built my own.&lt;/p&gt;

&lt;p&gt;This is the story of how I built Tracetics — a funnel analytics engine for developers — and the technical decisions behind it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Core Problem
&lt;/h2&gt;

&lt;p&gt;Funnel analytics sounds simple: a user does A, then B, then C. What percentage make it from A to C? Where do they drop off?&lt;/p&gt;

&lt;p&gt;In practice, it's surprisingly tricky to build well:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Events arrive asynchronously and out of order&lt;/li&gt;
&lt;li&gt;Funnels need to be flexible — different steps, different timeframes&lt;/li&gt;
&lt;li&gt;Calculation needs to be fast, even with thousands of events&lt;/li&gt;
&lt;li&gt;The integration overhead for the developer must be minimal&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My goal: a developer should be able to start tracking in under 5 minutes with a single HTTP POST.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture Overview
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Browser/App → REST API → Event Storage → Queue → Funnel Engine → Dashboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend:&lt;/strong&gt; Laravel 12 with a modular architecture (nwidart/laravel-modules)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Queue:&lt;/strong&gt; Laravel Horizon + Redis&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend:&lt;/strong&gt; Next.js 14 + TypeScript&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database:&lt;/strong&gt; MariaDB&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payments:&lt;/strong&gt; Stripe&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The API Layer
&lt;/h2&gt;

&lt;p&gt;The integration is intentionally minimal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST /api/v1/events
X-OL-Tenant-Key: your-tenant-key
X-OL-App-Key: your-app-key
Content-Type: application/json

{
  "event_name": "signup_completed",
  "user_identifier": "user_123",
  "metadata": {
    "plan": "pro",
    "source": "landing_page"
  }
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two headers, one JSON body. That's the entire contract.&lt;/p&gt;

&lt;p&gt;The controller validates the keys, identifies the tenant and tracked app, persists the event, and immediately returns 200. No heavy lifting in the request lifecycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Funnel Engine
&lt;/h2&gt;

&lt;p&gt;This is where it gets interesting.&lt;/p&gt;

&lt;p&gt;When a user builds a funnel in the dashboard — say "visited_pricing → started_trial → upgraded" — the system needs to calculate conversion rates for each step.&lt;/p&gt;

&lt;p&gt;I deliberately moved this out of the request cycle entirely. Every event write dispatches a background job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;ProcessFunnelEngineJob&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;onQueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'funnels'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The job picks up the event, loads all funnels for that app, and recalculates conversion rates per step using a sliding window approach. Results are cached and served to the dashboard.&lt;/p&gt;

&lt;p&gt;Why a queue? Two reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt; — The API response stays fast regardless of how many funnels need recalculation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resilience&lt;/strong&gt; — Failed jobs retry automatically, no data loss on transient errors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Laravel Horizon gives us a real-time dashboard to monitor job throughput, failed jobs, and queue depth without any additional infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Tenancy
&lt;/h2&gt;

&lt;p&gt;Tracetics is multi-tenant by design. Each tenant (company) can have multiple TrackedApps, each with their own events and funnels. The key hierarchy looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tenant
  └── TrackedApp (X-OL-App-Key)
        └── Events
        └── Funnels
              └── FunnelSteps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Authentication at the API level uses two headers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;X-OL-Tenant-Key&lt;/code&gt; — identifies the tenant&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;X-OL-App-Key&lt;/code&gt; — identifies which app the event belongs to&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This keeps the integration clean on the developer side while enforcing strict data isolation on the backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plan Limits &amp;amp; Billing
&lt;/h2&gt;

&lt;p&gt;Each plan defines limits for TrackedApps, Funnels, and monthly Events. These are enforced at the controller level before any write operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$tenant&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;trackedApps&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nv"&gt;$tenant&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;app_limit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'error'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'App limit reached'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stripe handles subscriptions via webhooks. The interesting challenge here: Stripe's newer API moved &lt;code&gt;current_period_end&lt;/code&gt; into &lt;code&gt;items.data[0]&lt;/code&gt; rather than the subscription root object. A subtle breaking change that cost me an hour of debugging.&lt;/p&gt;

&lt;h2&gt;
  
  
  The TypeScript SDK
&lt;/h2&gt;

&lt;p&gt;For developers who prefer typed clients over raw HTTP, I published a TypeScript SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;tracetics-sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Tracetics&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tracetics-sdk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Tracetics&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;tenantKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-tenant-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;trackedAppKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-app-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://tracetics.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;track&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;event_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;signup_completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;user_identifier&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user_123&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The SDK is built with tsup — dual ESM/CJS output, full TypeScript types, zero dependencies.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Keep the write path dumb and fast.&lt;/strong&gt;&lt;br&gt;
The API should do as little as possible. Validate, persist, enqueue. Everything else is the queue's problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Queue-first architecture pays off immediately.&lt;/strong&gt;&lt;br&gt;
I never had to worry about slow funnel calculations blocking API responses. The separation of concerns made both sides easier to reason about and debug.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Stripe webhooks are not optional.&lt;/strong&gt;&lt;br&gt;
I made the mistake early on of relying only on redirect-based confirmation. Webhooks are the only reliable source of truth for subscription state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Multi-tenancy is easier with a clear key hierarchy.&lt;/strong&gt;&lt;br&gt;
Having explicit Tenant → App → Event ownership made permission checking trivial and data isolation bulletproof.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;Tracetics is live at &lt;a href="https://tracetics.com" rel="noopener noreferrer"&gt;tracetics.com&lt;/a&gt; with a free plan available. The TypeScript SDK is on npm as &lt;code&gt;tracetics-sdk&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you've built something similar or have questions about the architecture, I'd love to hear from you in the comments.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>analytics</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
