<?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"><channel><title><![CDATA[Akshay Nikhare - Blog ]]></title><description><![CDATA[Akshay Nikhare - Blog ]]></description><link>https://akshaynikhare.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 22:09:55 GMT</lastBuildDate><atom:link href="https://akshaynikhare.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[onPreviewKeyEvent vs onKeyEvent on Android TV: A Subtle D-Pad Bug]]></title><description><![CDATA[The bug report was simple: long-pressing the d-pad center button on a channel card should toggle the favorite — it wasn't working reliably. On some devices…]]></description><link>https://akshaynikhare.hashnode.dev/onpreviewkeyevent-vs-onkeyevent-on-android-tv-a-subtle-d-pad-bug</link><guid isPermaLink="true">https://akshaynikhare.hashnode.dev/onpreviewkeyevent-vs-onkeyevent-on-android-tv-a-subtle-d-pad-bug</guid><category><![CDATA[android tv]]></category><category><![CDATA[Jetpack Compose]]></category><category><![CDATA[Kotlin]]></category><category><![CDATA[Android]]></category><category><![CDATA[Input Handling]]></category><dc:creator><![CDATA[akshay Nikhare]]></dc:creator><pubDate>Fri, 24 Jul 2026 17:24:17 GMT</pubDate><content:encoded><![CDATA[<p>The bug report was simple: long-pressing the d-pad center button on a channel card should toggle the favorite — it wasn't working reliably. On some devices it fired once and stopped. On others it didn't fire at all on long-press.</p>
<p>The fix was changing <code>onKeyEvent</code> to <code>onPreviewKeyEvent</code> in one Composable. The reason why is worth understanding.</p>
<h2>Background: Two Event Handlers in Compose</h2>
<p>Jetpack Compose exposes two modifier-level hooks for key input:</p>
<pre><code class="language-kotlin">Modifier.onKeyEvent { keyEvent -&gt; ... }
Modifier.onPreviewKeyEvent { keyEvent -&gt; ... }
</code></pre>
<p>They sound equivalent. They're not. The difference is <strong>where they sit in the event propagation chain</strong>.</p>
<h2>How Android TV Routes D-Pad Events</h2>
<p>When a user presses a key on a TV remote, Android routes the event through a dispatch tree:</p>
<pre><code>Activity
└─ ViewGroup (root)
   └─ FocusedComposable
      └─ Child Composables
</code></pre>
<p>The event travels <strong>down</strong> first (capture phase), then <strong>up</strong> (bubble phase):</p>
<ol>
<li><strong>Capture (top → focused node):</strong> <code>onPreviewKeyEvent</code> handlers fire here, outermost first.</li>
<li><strong>Bubble (focused node → top):</strong> <code>onKeyEvent</code> handlers fire here, innermost first.</li>
</ol>
<p><code>onPreviewKeyEvent</code> is the capture phase. <code>onKeyEvent</code> is the bubble phase.</p>
<h2>Why This Matters for Long-Press</h2>
<p>Android TV handles long-press recognition at the framework level. When you hold the d-pad center button:</p>
<ol>
<li>A <code>KeyEvent.ACTION_DOWN</code> fires immediately.</li>
<li>If the key is held, the framework generates repeated <code>ACTION_DOWN</code> events at the key repeat rate.</li>
<li><code>ACTION_UP</code> fires when the button is released.</li>
</ol>
<p>The long-press callback that Compose's focus system uses for "confirm" actions (select, activate) consumes <code>ACTION_DOWN</code> during the bubble phase — specifically to prevent the holding action from also triggering the tap action.</p>
<p>When the <code>ChannelCard</code> had a click handler wired for the primary action and <code>onKeyEvent</code> for the long-press toggle, the click handler's bubble-phase consumption of <code>ACTION_DOWN</code> was racing with the long-press handler. On some devices the click handler won, swallowing the event before the long-press code ran.</p>
<h2>The Fix</h2>
<p>Before:</p>
<pre><code class="language-kotlin">Modifier.onKeyEvent { keyEvent -&gt;
    if (keyEvent.key == Key.DirectionCenter &amp;&amp;
        keyEvent.type == KeyEventType.KeyDown &amp;&amp;
        keyEvent.isLongPress) {
        onToggleFavorite()
        true
    } else {
        false
    }
}
</code></pre>
<p>After:</p>
<pre><code class="language-kotlin">Modifier.onPreviewKeyEvent { keyEvent -&gt;
    if (keyEvent.key == Key.DirectionCenter &amp;&amp;
        keyEvent.type == KeyEventType.KeyDown &amp;&amp;
        keyEvent.isLongPress) {
        onToggleFavorite()
        true
    } else {
        false
    }
}
</code></pre>
<p><code>onPreviewKeyEvent</code> intercepts the event during the capture phase — before any child or peer handler gets a chance to consume it. The long-press fires cleanly, and returning <code>true</code> stops the event from propagating further, so the normal click action doesn't also trigger.</p>
<h2>When to Use Each</h2>
<table>
<thead>
<tr>
<th>Situation</th>
<th>Use</th>
</tr>
</thead>
<tbody><tr>
<td>Reacting to a key after children have had first chance</td>
<td><code>onKeyEvent</code></td>
</tr>
<tr>
<td>Intercepting a key before children or peer handlers see it</td>
<td><code>onPreviewKeyEvent</code></td>
</tr>
<tr>
<td>Global shortcuts that should always fire regardless of focus</td>
<td><code>onPreviewKeyEvent</code> on a parent</td>
</tr>
<tr>
<td>Input that should only fire when no child claimed it</td>
<td><code>onKeyEvent</code> on a parent</td>
</tr>
<tr>
<td>Long-press that conflicts with click on the same node</td>
<td><code>onPreviewKeyEvent</code></td>
</tr>
</tbody></table>
<p>The rule of thumb: if a click handler and a key handler live on the same composable and the key handler is for a long-press or a secondary action, use <code>onPreviewKeyEvent</code> to get in before the click machinery.</p>
<h2>A Note on <code>isLongPress</code></h2>
<p>The <code>isLongPress</code> property on <code>KeyEvent</code> in Compose isn't always reliable across all Android TV hardware. A more robust approach uses elapsed time:</p>
<pre><code class="language-kotlin">var keyDownTime = 0L

Modifier.onPreviewKeyEvent { keyEvent -&gt;
    when {
        keyEvent.key == Key.DirectionCenter &amp;&amp; keyEvent.type == KeyEventType.KeyDown -&gt; {
            if (keyDownTime == 0L) keyDownTime = System.currentTimeMillis()
            val held = System.currentTimeMillis() - keyDownTime
            if (held &gt;= 500L) {
                onToggleFavorite()
                keyDownTime = 0L
                true
            } else false
        }
        keyEvent.key == Key.DirectionCenter &amp;&amp; keyEvent.type == KeyEventType.KeyUp -&gt; {
            keyDownTime = 0L
            false
        }
        else -&gt; false
    }
}
</code></pre>
<p>This measures elapsed hold time manually, which is consistent across the wide range of Android TV hardware — from budget HDMI sticks to mid-range smart TVs — where key repeat rates and long-press thresholds vary.</p>
<h2>Summary</h2>
<p><code>onKeyEvent</code> and <code>onPreviewKeyEvent</code> are not interchangeable. If you're building interactive cards on Android TV and a long-press isn't firing reliably, the cause is almost certainly event consumption order. Move to <code>onPreviewKeyEvent</code> and intercept before the bubble phase claims the event.</p>
]]></content:encoded></item><item><title><![CDATA[The x-tenant-id Pattern: Multi-Tenant API Without Multi-Tenant Complexity]]></title><description><![CDATA[When you're building a multi-tenant SaaS, the first architectural question is usually: how do you keep tenant data isolated? The options range from…]]></description><link>https://akshaynikhare.hashnode.dev/the-x-tenant-id-pattern-multi-tenant-api-without-multi-tenant-complexity</link><guid isPermaLink="true">https://akshaynikhare.hashnode.dev/the-x-tenant-id-pattern-multi-tenant-api-without-multi-tenant-complexity</guid><category><![CDATA[Multi tenancy]]></category><category><![CDATA[API Design]]></category><category><![CDATA[node]]></category><category><![CDATA[Express]]></category><category><![CDATA[JWT]]></category><dc:creator><![CDATA[akshay Nikhare]]></dc:creator><pubDate>Fri, 24 Jul 2026 17:24:04 GMT</pubDate><content:encoded><![CDATA[<p>When you're building a multi-tenant SaaS, the first architectural question is usually: how do you keep tenant data isolated? The options range from separate databases per tenant (maximum isolation, maximum cost) to a shared database with row-level filtering (minimum cost, more careful coding required).</p>
<p>But there's an equally important question that gets less attention: <strong>how does your API know which tenant context a request belongs to?</strong></p>
<p>This post covers a pattern we've used in production: a custom request header for tenant scoping, combined with JWT authentication. Simple to implement, easy to audit, and flexible enough to support multi-tenant access from a single user account.</p>
<h2>The Three Common Approaches</h2>
<h3>1. Subdomain-based (<code>tenant.yourdomain.com</code>)</h3>
<p>The tenant is encoded in the hostname. Each subdomain routes to the same backend, which extracts the tenant from the <code>Host</code> header.</p>
<p><strong>Good:</strong> Intuitive, visible in the URL. <strong>Bad:</strong> Requires wildcard TLS certs, more complex DNS setup, awkward in development, doesn't work for mobile API clients the same way.</p>
<h3>2. URL path-based (<code>/api/tenants/{tenantId}/...</code>)</h3>
<p>The tenant identifier is part of every route path.</p>
<p><strong>Good:</strong> RESTful, self-documenting. <strong>Bad:</strong> Bloats all route definitions, requires every endpoint to include the tenant segment, makes API versioning messier.</p>
<h3>3. Header-based (<code>x-tenant-id: &lt;id&gt;</code>)</h3>
<p>A custom header carries the tenant context. Routes stay clean. The tenant scope is resolved in middleware before the handler runs.</p>
<p><strong>Good:</strong> Routes stay simple, middleware handles scoping uniformly, works well with JWT auth, easy to test. <strong>Bad:</strong> Less visible (the tenant isn't in the URL), requires clients to always include the header.</p>
<p>We use the header approach.</p>
<h2>The Implementation</h2>
<p>The API accepts two forms of auth:</p>
<ol>
<li>A JWT token in the <code>Authorization</code> header — identifies <em>who</em> is making the request</li>
<li>A tenant ID in the <code>x-tenant-id</code> header — identifies <em>on behalf of which tenant</em></li>
</ol>
<pre><code class="language-http">POST /api/v1/members
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
x-tenant-id: tenant_01GZ8K3X7Y
Content-Type: application/json
</code></pre>
<h3>Middleware</h3>
<p>Auth middleware runs first and validates the JWT. Tenant middleware runs second and validates the <code>x-tenant-id</code> against the authenticated user's permitted tenants:</p>
<pre><code class="language-javascript">// middleware/requireAuth.js
export async function requireAuth(req, res, next) {
  const token = extractBearerToken(req.headers.authorization);
  if (!token) return res.status(401).json({ error: 'Unauthorized' });

  try {
    const payload = verifyJwt(token);
    req.user = payload;
    next();
  } catch {
    res.status(401).json({ error: 'Invalid token' });
  }
}
</code></pre>
<pre><code class="language-javascript">// middleware/requireTenantContext.js
export async function requireTenantContext(req, res, next) {
  const tenantId = req.headers['x-tenant-id'];
  if (!tenantId) return res.status(400).json({ error: 'x-tenant-id header required' });

  // Verify the authenticated user has access to this tenant
  const membership = await db.membership.findFirst({
    where: {
      userId: req.user.id,
      tenantId,
      status: 'active',
    },
  });

  if (!membership) return res.status(403).json({ error: 'Access denied' });

  req.tenantId = tenantId;
  req.role = membership.role;
  next();
}
</code></pre>
<p>Route handlers then have <code>req.tenantId</code> and <code>req.role</code> available. All database queries in those handlers include <code>where: { tenantId: req.tenantId }</code>.</p>
<h3>Route Registration</h3>
<p>Tenant-scoped routes apply both middlewares. Public routes (auth endpoints, health checks) apply neither:</p>
<pre><code class="language-javascript">// Public
router.post('/auth/login', loginHandler);
router.get('/health', healthHandler);

// Tenant-scoped
router.use('/members', requireAuth, requireTenantContext, membersRouter);
router.use('/invoices', requireAuth, requireTenantContext, invoicesRouter);
router.use('/settings', requireAuth, requireTenantContext, settingsRouter);
</code></pre>
<p>Middleware is applied at the router level, not per-handler. New routes under a tenant-scoped prefix automatically inherit the context without any extra work.</p>
<h2>Multi-Tenant Access From One Account</h2>
<p>The header pattern makes something else easy: a single user account accessing multiple tenants.</p>
<p>A super-admin or management tool needs to query across tenants or switch context without re-authenticating. With the header pattern this is trivial — issue one JWT for the user, then pass different <code>x-tenant-id</code> values per request:</p>
<pre><code class="language-javascript">// Management dashboard switching tenant context
async function fetchMembersForTenant(tenantId) {
  return api.get('/members', {
    headers: {
      'Authorization': `Bearer ${userToken}`,
      'x-tenant-id': tenantId,
    }
  });
}
</code></pre>
<p>With subdomain or path-based approaches, the same scenario requires different base URLs or duplicated route structures.</p>
<h2>Adding Defense-in-Depth: Row-Level Security</h2>
<p>The header + middleware pattern handles application-layer tenant isolation. For an additional layer at the database level, PostgreSQL's Row-Level Security can enforce isolation even if a bug in application code omits a <code>tenantId</code> filter:</p>
<pre><code class="language-sql">-- Policy: users can only see rows belonging to their current tenant
ALTER TABLE members ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON members
  USING (tenant_id = current_setting('app.current_tenant_id')::uuid);
</code></pre>
<p>At the start of each request, set the current tenant on the DB connection:</p>
<pre><code class="language-javascript">await db.$executeRaw`SELECT set_config('app.current_tenant_id', ${req.tenantId}, true)`;
</code></pre>
<p>Now even a query that forgets <code>WHERE tenant_id = ?</code> returns empty results instead of leaking data. The middleware is the first line of defense; RLS is the backstop.</p>
<h2>Tradeoffs to Know Before Adopting</h2>
<p><strong>Clients must always send the header.</strong> This is a discipline requirement. Forgetting the header returns a 400, which is fast to debug, but it's a paper cut during initial integration. Document it clearly and consider a helpful error message: <code>"x-tenant-id header is required for this endpoint. See docs for details."</code></p>
<p><strong>The header is visible in logs.</strong> Tenant IDs aren't secrets — they're identifiers — but make sure your log sanitization rules treat them consistently with other metadata.</p>
<p><strong>Switching tenants mid-session is application-layer logic.</strong> The API doesn't know or care about "the current tenant" in session state. The client always tells the API which tenant context to use. This is explicit, which is good, but requires the client to manage that state.</p>
<h2>Summary</h2>
<p>The <code>x-tenant-id</code> header pattern is not glamorous, but it's effective. Routes stay clean. Middleware handles scoping uniformly. A single JWT works across multiple tenant contexts. And the pattern composes naturally with database-level isolation when you need it.</p>
<p>For most multi-tenant APIs where tenants are organizations (not individual users), this pattern is worth considering before reaching for the subdomain or path-based alternatives.</p>
]]></content:encoded></item><item><title><![CDATA[Mono-Repo + Multi-Repo: How We Structured 6 Apps Across 4 Repositories]]></title><description><![CDATA[Most teams treat "monorepo vs multi-repo" as a binary choice. Pick one, commit, move on. We ended up with a hybrid, and it turned out to be the right call…]]></description><link>https://akshaynikhare.hashnode.dev/mono-repo-multi-repo-how-we-structured-6-apps-across-4-repositories</link><guid isPermaLink="true">https://akshaynikhare.hashnode.dev/mono-repo-multi-repo-how-we-structured-6-apps-across-4-repositories</guid><category><![CDATA[monorepo]]></category><category><![CDATA[multi-repo]]></category><category><![CDATA[ci-cd]]></category><category><![CDATA[mobile]]></category><category><![CDATA[React Native]]></category><dc:creator><![CDATA[akshay Nikhare]]></dc:creator><pubDate>Fri, 24 Jul 2026 17:23:41 GMT</pubDate><content:encoded><![CDATA[<p>Most teams treat "monorepo vs multi-repo" as a binary choice. Pick one, commit, move on. We ended up with a hybrid, and it turned out to be the right call — not out of indecision, but because our apps have genuinely different deployment and ownership characteristics.</p>
<p>Here's what we built, why, and what it costs.</p>
<h2>The System</h2>
<p>The platform consists of six applications:</p>
<table>
<thead>
<tr>
<th>App</th>
<th>Type</th>
<th>Primary Users</th>
</tr>
</thead>
<tbody><tr>
<td>REST API backend</td>
<td>Node.js + TypeScript</td>
<td>— (consumed by all apps)</td>
</tr>
<tr>
<td>Society dashboard</td>
<td>React web app</td>
<td>Society managers, admins, accountants</td>
</tr>
<tr>
<td>Company admin panel</td>
<td>React web app</td>
<td>Internal operations</td>
</tr>
<tr>
<td>Marketing website</td>
<td>Next.js</td>
<td>Public</td>
</tr>
<tr>
<td>Resident mobile app</td>
<td>React Native (Expo)</td>
<td>Residents</td>
</tr>
<tr>
<td>Guard mobile app</td>
<td>React Native (Expo)</td>
<td>Security personnel</td>
</tr>
</tbody></table>
<p>All six apps talk to the same API. But they have very different deployment cycles, team ownership, and testing requirements.</p>
<h2>The Structure: 4 Repositories</h2>
<pre><code>repo: main-platform (monorepo)
├── api/ — Express + Prisma backend
├── web-society/ — Society dashboard
├── web-admin/ — Company admin panel
└── web-marketing/ — Marketing site

repo: mobile-resident — Resident app (React Native)
repo: mobile-guard — Guard app (React Native)
repo: mobile-staff — Society staff mobile app (React Native)
</code></pre>
<p>The web apps and the API live together in one monorepo. The three mobile apps each have their own repository.</p>
<h2>Why Split Mobile From Web?</h2>
<p>The driving factor was <strong>deployment cadence and review process</strong>.</p>
<p>Web apps deploy on push — merge to main, CI builds, CDN updated within minutes. The feedback loop is fast, rollbacks are instant, and there's no approval gate between code and production.</p>
<p>Mobile apps go through app store review. A release cycle includes building a release APK, submitting to Google Play (and Apple App Store), waiting for review, and then a staged rollout. The cadence is measured in days, not minutes. Mistakes are expensive to reverse — a bad release means submitting a patch, waiting again, and potentially having a broken version live for days.</p>
<p>Given that difference, mobile releases warrant a separate release workflow, separate versioning (<code>release-please</code> per repo), separate EAS build config, and a dedicated changelog. Bundling mobile with web would mean mobile releases dragging along unrelated web changes and making the release notes hard to read.</p>
<p><strong>Separate repos give each mobile app its own clean release history.</strong></p>
<h2>Why Keep the Backend and Web Apps Together?</h2>
<p>Because they change together constantly.</p>
<p>Most features touch both the API and a web frontend. A new billing feature means a new API endpoint, a new React page, and updates to both. With the API and web apps in the same repo:</p>
<ul>
<li>One PR covers the full change</li>
<li>The CI pipeline validates everything together</li>
<li>Reviewing a PR gives you the complete picture</li>
<li>No cross-repo issue tracking for basic feature work</li>
</ul>
<p>If they were in separate repos, every feature PR would spawn linked PRs across two repositories — more coordination overhead for changes that are logically one unit.</p>
<h2>The Cross-Repo Challenge</h2>
<p>The seam between repos is where friction lives.</p>
<p>When a new API endpoint or a modified contract affects mobile apps, you get cross-repo work: one PR in the main platform repo, one or more PRs in the mobile repos. We handle this with explicit cross-linking:</p>
<ul>
<li>The parent issue lives in the main repo</li>
<li>Each mobile repo gets a child issue referencing back</li>
<li>PRs on both sides link to the same parent issue</li>
</ul>
<p>It works, but it requires discipline. The worst version of this is when someone merges an API change without checking whether the mobile apps need a corresponding update. To guard against that, breaking API changes go through a separate review step that explicitly asks: "which mobile app versions does this affect, and are those PRs in flight?"</p>
<h2>Branch Protection Across All Repos</h2>
<p>All four repos have identical branch protection on <code>main</code>:</p>
<ul>
<li>No direct pushes</li>
<li>At least one approving review required</li>
<li>CI must pass before merge</li>
</ul>
<p>This is non-negotiable. With a multi-repo setup, it's easy for protection rules to diverge between repos. Keeping them identical means the same habits apply regardless of which repo you're working in.</p>
<h2>Shared Dependencies and Drift</h2>
<p>The main risk with multi-repo mobile apps is dependency drift. Each mobile repo has its own <code>package.json</code>. If <code>main-platform</code> bumps a shared utility, the mobile repos don't automatically follow.</p>
<p>Our mitigation: the Expo SDK version and key shared dependencies (React Native, TypeScript, Babel config) are pinned to the same versions across all mobile repos. We check this in a periodic sync script rather than trying to enforce it automatically — automatic enforcement across repos adds tooling complexity we haven't needed yet.</p>
<h2>What We'd Do Differently</h2>
<p><strong>Better automation for cross-repo issues.</strong> Manually linking parent and child issues works until someone forgets. A GitHub Action that opens draft child issues in mobile repos when a label is applied to a main-repo issue would remove that failure mode.</p>
<p><strong>Shared TypeScript types package.</strong> API response types are currently duplicated between the backend, web apps, and mobile apps. A shared <code>@platform/types</code> internal package published to a private registry (or referenced via workspace) would make type drift detectable at compile time. We've planned this but haven't needed it badly enough to prioritize it yet.</p>
<p><strong>Document the structure early.</strong> The hybrid structure is intuitive once you understand the reasoning, but onboarding a new contributor requires explaining why mobile lives in separate repos. A <code>REPOS.md</code> at the root of the main repo — linking out and explaining the structure — saves the first 10 minutes of every onboarding conversation.</p>
<h2>The Summary</h2>
<table>
<thead>
<tr>
<th>Characteristic</th>
<th>Monorepo (web + API)</th>
<th>Multi-repo (mobile)</th>
</tr>
</thead>
<tbody><tr>
<td>Deployment cadence</td>
<td>Continuous (minutes)</td>
<td>Store review (days)</td>
</tr>
<tr>
<td>Typical change scope</td>
<td>Multi-file, multi-layer</td>
<td>Self-contained per app</td>
</tr>
<tr>
<td>Release notes</td>
<td>Combined</td>
<td>Per app</td>
</tr>
<tr>
<td>PR complexity</td>
<td>High — covers whole feature</td>
<td>Focused</td>
</tr>
<tr>
<td>Cross-team coordination</td>
<td>Implicit (same repo)</td>
<td>Explicit (issue links)</td>
</tr>
</tbody></table>
<p>Monorepos reduce coordination overhead for tightly coupled code. Multi-repo reduces noise for code that releases independently. The answer isn't one or the other — it's matching your repo structure to your actual deployment and ownership boundaries.</p>
]]></content:encoded></item><item><title><![CDATA[FireViston TV: Android App & Streaming Server for the Living Room]]></title><description><![CDATA[Live Project: tv.cadnative.com FireViston TV is a full-stack streaming solution designed for the modern living room. It consists of two parts that work in…]]></description><link>https://akshaynikhare.hashnode.dev/fireviston-tv-android-app-streaming-server-for-the-living-room</link><guid isPermaLink="true">https://akshaynikhare.hashnode.dev/fireviston-tv-android-app-streaming-server-for-the-living-room</guid><category><![CDATA[fireviston]]></category><category><![CDATA[android tv]]></category><category><![CDATA[streaming]]></category><category><![CDATA[video]]></category><category><![CDATA[server]]></category><dc:creator><![CDATA[akshay Nikhare]]></dc:creator><pubDate>Fri, 24 Jul 2026 17:23:21 GMT</pubDate><content:encoded><![CDATA[<p><strong>Live Project:</strong> <a href="https://tv.cadnative.com/">tv.cadnative.com</a></p>
<hr />
<h2>What Is FireViston TV?</h2>
<p><strong>FireViston TV</strong> is a full-stack streaming solution designed for the modern living room. It consists of two parts that work in tight coordination:</p>
<ol>
<li><strong>FireViston TV Android App</strong> — a native Android/Android TV application that delivers a polished, remote-friendly viewing experience. <a href="https://github.com/akshaynikhare/FireVisionIPTV/releases">https://github.com/akshaynikhare/FireVisionIPTV/releases</a></li>
<li><strong>FireViston TV Server</strong> — the backend streaming infrastructure that powers content delivery, user management, and playback control hosted at <a href="https://tv.cadnative.com/">tv.cadnative.com</a></li>
</ol>
<p>Together, they form a complete, self-contained streaming platform.</p>
<h2>The Android App</h2>
<h3>Built for the 10-Foot Experience</h3>
<p>The FireViston Android app is designed for television screens — large fonts, d-pad navigation, and a layout that works from across the room. No pinching, no scrolling hunts, no mobile-style UI crammed onto a 55-inch display.</p>
<h3>Smooth Playback</h3>
<p>Video streaming requires more than just playing a file. FireViston handles adaptive bitrate streaming, buffer management, and codec compatibility to ensure smooth playback across the broadest range of Android TV devices — from budget sticks to high-end smart TVs.</p>
<h3>Content Discovery</h3>
<p>A clean, browsable content grid lets users find what they want quickly. Categories, search, and a "continue watching" row reduce friction from intent to playback.</p>
<h2>The Server Backend</h2>
<h3>Reliable Infrastructure</h3>
<p>The FireViston server at <a href="https://tv.cadnative.com/">tv.cadnative.com</a> manages content ingestion, transcoding pipelines, and delivery. It's built to handle concurrent streams without degrading quality for any individual viewer.</p>
<h3>API-Driven Architecture</h3>
<p>The Android app communicates with the server through a REST API, making the backend flexible enough to support additional clients — web players, other mobile platforms — without rewriting core logic.</p>
<h3>User &amp; Session Management</h3>
<p>Account creation, authentication, playback progress sync, and device management all happen server-side. Users can pick up on any device exactly where they left off.</p>
<h2>Why a Custom Streaming Stack?</h2>
<p>Off-the-shelf streaming platforms come with constraints: content policies, revenue sharing, limited branding control, and dependence on third-party availability.</p>
<p>FireViston TV gives full control — over the content, the experience, and the infrastructure. For operators who need that ownership, it's the right choice.</p>
<h2>Get FireViston TV</h2>
<ul>
<li><strong>Android App:</strong> Available for Android and Android TV devices</li>
<li><strong>Streaming Server:</strong> <a href="https://tv.cadnative.com/">tv.cadnative.com</a></li>
</ul>
]]></content:encoded></item><item><title><![CDATA[How a Single beforeEach Killed Our CI for 36 Hours]]></title><description><![CDATA[Six failed CI runs. Thirty-six hours of GitHub Actions time. Every run timing out at exactly the 6-hour limit. The culprit was one line in tests/setup.js…]]></description><link>https://akshaynikhare.hashnode.dev/how-a-single-beforeeach-killed-our-ci-for-36-hours</link><guid isPermaLink="true">https://akshaynikhare.hashnode.dev/how-a-single-beforeeach-killed-our-ci-for-36-hours</guid><category><![CDATA[Testing]]></category><category><![CDATA[ci-cd]]></category><category><![CDATA[PostgreSQL]]></category><category><![CDATA[GitHub Actions]]></category><category><![CDATA[node]]></category><category><![CDATA[performance]]></category><dc:creator><![CDATA[akshay Nikhare]]></dc:creator><pubDate>Fri, 24 Jul 2026 07:16:20 GMT</pubDate><content:encoded><![CDATA[<p>Six failed CI runs. Thirty-six hours of GitHub Actions time. Every run timing out at exactly the 6-hour limit.</p>
<p>The culprit was one line in <code>tests/setup.js</code>.</p>
<h2>The Setup</h2>
<p>We were building a multi-tenant platform with a PostgreSQL backend — around 76 database models handling everything from user accounts and billing to visitor logs and real-time notifications. The test suite had grown to roughly 1,140 test cases across 36 files.</p>
<p>Standard stuff. CI ran on every PR. Tests passed locally. And then one day, CI just… never finished.</p>
<h2>The Anti-Pattern</h2>
<p>Here's what the test setup looked like:</p>
<pre><code class="language-javascript">// tests/setup.js
beforeEach(async () =&gt; {
  const tableNames = await getTableNames(); // 76 tables
  await sequelize.query(
    `TRUNCATE TABLE ${tableNames.join(', ')} CASCADE;`
  );
});
</code></pre>
<p>The intent was clean isolation — every test starts with a blank slate. Reasonable in theory. Catastrophic in practice.</p>
<h2>The Math</h2>
<p>Do the multiplication:</p>
<pre><code>76 tables × 1,140 tests = 86,640 TRUNCATE operations
</code></pre>
<p>Each <code>TRUNCATE TABLE ... CASCADE</code> is not a cheap operation. PostgreSQL has to:</p>
<ol>
<li>Acquire exclusive locks on all referenced tables</li>
<li>Walk the foreign key graph to find dependent tables</li>
<li>Truncate each in dependency order</li>
<li>Release locks</li>
</ol>
<p>With a moderately complex schema where most tables reference others (users → societies → members → invoices → payments → …), a single <code>TRUNCATE ... CASCADE</code> on a central table can fan out into dozens of implicit truncations.</p>
<p>Multiply that by 86,640 and you have a test suite that will never complete within any reasonable timeout.</p>
<h2>Why It Wasn't Caught Sooner</h2>
<p>Two reasons:</p>
<p><strong>1. It used to be fast.</strong> When the suite had 50 tests and 20 tables, this pattern worked fine. <code>50 × 20 = 1,000</code> truncations — uncomfortable but survivable. Nobody noticed when the suite crossed a tipping point.</p>
<p><strong>2. Local runs used a different database state.</strong> Locally, developers often ran a subset of tests with <code>--grep</code> or file-specific runs. The full suite was only ever run on CI, and CI was slow enough that most assumed it was just a "CI is slow" problem rather than a runaway complexity issue.</p>
<h2>The Fix</h2>
<p>Three changes, applied together:</p>
<h3>1. Move sync to <code>beforeAll</code>, not <code>beforeEach</code></h3>
<pre><code class="language-javascript">// tests/setup.js — AFTER
beforeAll(async () =&gt; {
  await sequelize.sync({ force: true }); // once per suite, not per test
});
</code></pre>
<p>Tables are created once at the start of the suite. No teardown between tests.</p>
<h3>2. Use unique identifiers in test data</h3>
<p>Without per-test cleanup, tests can no longer share fixed data. The fix is to make every piece of test data unique:</p>
<pre><code class="language-javascript">// BEFORE — breaks without cleanup
const user = await createTestUser({ email: 'test@example.com' });

// AFTER — safe without cleanup
const user = await createTestUser({ email: `user_${Date.now()}_${Math.random().toString(36).slice(2)}@test.com` });
</code></pre>
<p>Timestamps and short random suffixes make collisions statistically impossible across a test run. UUIDs work too — use whatever your helpers already produce.</p>
<h3>3. Add CI timeout safety nets</h3>
<p>The default GitHub Actions job timeout is 6 hours. That's a very long time to wait before learning something is wrong. Set explicit timeouts on test steps:</p>
<pre><code class="language-yaml">- name: Run tests
  run: npm test
  timeout-minutes: 15
</code></pre>
<p>Now a runaway suite fails in 15 minutes instead of 6 hours. You get the signal fast and spend less Actions budget on it.</p>
<h2>Results</h2>
<table>
<thead>
<tr>
<th></th>
<th>Before</th>
<th>After</th>
</tr>
</thead>
<tbody><tr>
<td>TRUNCATE operations</td>
<td>86,640</td>
<td>0</td>
</tr>
<tr>
<td>Test suite duration</td>
<td>6+ hours (timeout)</td>
<td>~3 minutes</td>
</tr>
<tr>
<td>CI failure signal</td>
<td>After 6 hours</td>
<td>After 15 minutes max</td>
</tr>
</tbody></table>
<h2>When Transaction Rollback Is Better</h2>
<p>If your tests don't create their own transactions internally, wrapping each test in a transaction and rolling back is faster than <code>TRUNCATE</code> and safer than the unique-ID approach:</p>
<pre><code class="language-javascript">let transaction;

beforeEach(async () =&gt; {
  transaction = await sequelize.transaction();
});

afterEach(async () =&gt; {
  await transaction.rollback();
});
</code></pre>
<p>This works well for simpler schemas. We couldn't use it because several of our tested code paths opened their own transactions internally, which can't be nested without explicit savepoint support. The unique-ID approach was the safer choice for our case.</p>
<h2>The Underlying Lesson</h2>
<p>Test isolation strategies don't scale linearly — they scale with <code>tests × tables</code>. A pattern that works at 50 tests and 20 tables can fail spectacularly at 1,000 tests and 76 tables.</p>
<p>If your test suite is growing and CI is getting slower, check your setup/teardown strategy before assuming you need faster hardware.</p>
]]></content:encoded></item></channel></rss>