<?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: Gubaidulla Orynbekov</title>
    <description>The latest articles on DEV Community by Gubaidulla Orynbekov (@gubaidulla_orynbekov_e422).</description>
    <link>https://dev.to/gubaidulla_orynbekov_e422</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4110543%2F3548aa1a-0a3b-4b8d-b60d-6a78d7bfab9f.png</url>
      <title>DEV Community: Gubaidulla Orynbekov</title>
      <link>https://dev.to/gubaidulla_orynbekov_e422</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gubaidulla_orynbekov_e422"/>
    <language>en</language>
    <item>
      <title>The request before yours matters: testing cache isolation in both orders</title>
      <dc:creator>Gubaidulla Orynbekov</dc:creator>
      <pubDate>Sun, 29 Nov 2026 17:32:59 +0000</pubDate>
      <link>https://dev.to/gubaidulla_orynbekov_e422/the-request-before-yours-matters-testing-cache-isolation-in-both-orders-2427</link>
      <guid>https://dev.to/gubaidulla_orynbekov_e422/the-request-before-yours-matters-testing-cache-isolation-in-both-orders-2427</guid>
      <description>&lt;p&gt;Alice's test passes. Bob's test passes. Then Alice makes her request first, and Bob receives her dashboard.&lt;/p&gt;

&lt;p&gt;If you've worked on a multi-user or multi-tenant app with a cache in front of it, this bug probably looks familiar. This post covers why normal tests miss it, a small experiment that catches it, and the open-source CLI I built to run that experiment: &lt;strong&gt;&lt;a href="https://github.com/godz1llla/cachewitness" rel="noopener noreferrer"&gt;CacheWitness&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug fits in one line
&lt;/h2&gt;

&lt;p&gt;Here's the entire difference between the broken and fixed versions of the demo server that ships with the tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// broken: every user shares one cache entry&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'dashboard'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// fixed: the entry is scoped to the tenant&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`dashboard:${account.tenant}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same shape turns up all over the place:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a per-user response cached under a URL-only key,&lt;/li&gt;
&lt;li&gt;tenant settings cached without the tenant ID,&lt;/li&gt;
&lt;li&gt;a price cached without the &lt;code&gt;currency&lt;/code&gt; query parameter,&lt;/li&gt;
&lt;li&gt;a CDN or reverse proxy that ignores a header the app relies on (&lt;code&gt;Authorization&lt;/code&gt;, &lt;code&gt;Accept-Language&lt;/code&gt;, …).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why your tests stay green
&lt;/h2&gt;

&lt;p&gt;Most tests run &lt;strong&gt;one identity per test&lt;/strong&gt;, often against a fresh cache. Under those conditions the shared key is invisible: whoever asks first always gets their own data.&lt;/p&gt;

&lt;p&gt;The failure needs two things your test suite rarely combines:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;a &lt;strong&gt;different&lt;/strong&gt; identity primes the cache first, and&lt;/li&gt;
&lt;li&gt;the second identity asks for the &lt;strong&gt;same&lt;/strong&gt; endpoint before the entry expires.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So you need to test the &lt;em&gt;order&lt;/em&gt;, not just the identities.&lt;/p&gt;

&lt;h2&gt;
  
  
  The experiment
&lt;/h2&gt;

&lt;p&gt;CacheWitness tests one question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Does a target variant receive its normal response after a different variant primes the same endpoint?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You supply one JSON GET endpoint, two or more variants (headers and/or query params), and a synchronous reset endpoint for the test cache. Then:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Cold baselines.&lt;/strong&gt; For each variant, &lt;code&gt;reset → request → normalize JSON → fingerprint&lt;/code&gt;, repeated (twice by default). If the repetitions disagree, the baseline is unstable and the affected pairs are reported as &lt;em&gt;inconclusive&lt;/em&gt;, not passed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Every ordered pair.&lt;/strong&gt; For A and B:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;reset → A → A again → B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and separately &lt;code&gt;B → A&lt;/code&gt;. With &lt;code&gt;n&lt;/code&gt; variants that's &lt;code&gt;n × (n − 1)&lt;/code&gt; ordered checks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Compare.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Observation&lt;/th&gt;
&lt;th&gt;Verdict&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;B equals cold B&lt;/td&gt;
&lt;td&gt;pass&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B equals cold A&lt;/td&gt;
&lt;td&gt;contamination&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B matches neither&lt;/td&gt;
&lt;td&gt;drift (investigate)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;cold A equals cold B&lt;/td&gt;
&lt;td&gt;indistinguishable (inconclusive)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What it looks like
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cachewitness demo
CacheWitness — FAIL
2 variants · 2 ordered pairs · 16 HTTP requests
0 passed · 2 contamination · 0 drift · 0 indistinguishable · 0 unstable
  alice → bob: contamination
    Target received the source baseline instead of its own baseline.
    Changed fields: /body/balanceCents, /body/owner, /body/tenant
  bob → alice: contamination
    Target received the source baseline instead of its own baseline.
    Changed fields: /body/balanceCents, /body/owner, /body/tenant
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the fixed key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cachewitness demo --fixed
CacheWitness — PASS
2 variants · 2 ordered pairs · 16 HTTP requests
2 passed · 0 contamination · 0 drift · 0 indistinguishable · 0 unstable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--html report.html&lt;/code&gt; writes a single offline file with the pair matrix, baseline stability, and per-check evidence. Reports keep variant names, JSON pointer paths, and fingerprints. They &lt;strong&gt;don't&lt;/strong&gt; keep raw response values, credentials, or full URLs, so they're reasonable to attach to a CI run. (Field names and hashes can still be sensitive; the SECURITY.md covers this.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Put it in CI
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Check response isolation&lt;/span&gt;
  &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;godz1llla/cachewitness@v0.2.0&lt;/span&gt;
  &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;cachewitness.json&lt;/span&gt;
  &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;CACHEWITNESS_BASE_URL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http://127.0.0.1:3000&lt;/span&gt;
    &lt;span class="na"&gt;CACHEWITNESS_ALICE_TOKEN&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.TEST_ALICE_TOKEN }}&lt;/span&gt;
    &lt;span class="na"&gt;CACHEWITNESS_BOB_TOKEN&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.TEST_BOB_TOKEN }}&lt;/span&gt;
    &lt;span class="na"&gt;CACHEWITNESS_RESET_TOKEN&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.TEST_RESET_TOKEN }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Contamination, drift, or an inconclusive audit fails the job, and you get a job summary plus JSON/HTML reports to upload as artifacts. &lt;code&gt;cachewitness init --preset auth|tenant|currency&lt;/code&gt; generates a starting config.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it doesn't prove
&lt;/h2&gt;

&lt;p&gt;I'd rather be upfront about this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A witness isn't a root cause.&lt;/strong&gt; Shared session state, a mutable global, or a broken reset can produce the same output. The report tells you &lt;em&gt;what changed and in which order&lt;/em&gt;; you still trace &lt;em&gt;why&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A pass isn't universal isolation.&lt;/strong&gt; It covers the endpoint, variants, sequence, and compared fields you supplied. Concurrency and races aren't tested yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It doesn't see inside your cache.&lt;/strong&gt; It observes HTTP responses only.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;Node.js 22+, zero runtime dependencies, MIT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install --global https://github.com/godz1llla/cachewitness/releases/download/v0.2.0/godz1llla-cachewitness-0.2.0.tgz
cachewitness demo --html broken.html
cachewitness demo --fixed --html fixed.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first command exits with code 1 &lt;strong&gt;on purpose&lt;/strong&gt;: the demo server is deliberately broken.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/godz1llla/cachewitness" rel="noopener noreferrer"&gt;https://github.com/godz1llla/cachewitness&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you've hit a cache-isolation bug this sequence wouldn't catch, I'd love to hear about it in the comments or in an issue.&lt;/p&gt;

</description>
      <category>node</category>
      <category>webdev</category>
      <category>testing</category>
      <category>security</category>
    </item>
  </channel>
</rss>
