<?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: Jitsumi</title>
    <description>The latest articles on DEV Community by Jitsumi (@jitsumi).</description>
    <link>https://dev.to/jitsumi</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%2F4226611%2F6b838f8c-77f8-43d9-b7c5-10d0b5062d1b.png</url>
      <title>DEV Community: Jitsumi</title>
      <link>https://dev.to/jitsumi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jitsumi"/>
    <language>en</language>
    <item>
      <title>Your Save File Needs a Version Before It Needs More Fields</title>
      <dc:creator>Jitsumi</dc:creator>
      <pubDate>Mon, 23 Nov 2026 00:39:00 +0000</pubDate>
      <link>https://dev.to/jitsumi/your-save-file-needs-a-version-before-it-needs-more-fields-1046</link>
      <guid>https://dev.to/jitsumi/your-save-file-needs-a-version-before-it-needs-more-fields-1046</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feygsqcxqu96e1fj8ii73.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feygsqcxqu96e1fj8ii73.webp" alt="A brass key rests in a larger green specimen drawer beside an older, narrower drawer." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A save file can be valid JSON and still describe a world your current game no longer understands. Perhaps &lt;code&gt;coins&lt;/code&gt; became &lt;code&gt;wallet&lt;/code&gt;, an item changed its display name, or a level moved to a different scene path. Parsing succeeded; interpretation failed.&lt;/p&gt;

&lt;p&gt;Give the save format an explicit version, store durable identifiers for game content, and migrate older records into the current shape before applying them to the world. This article focuses on that data contract. It does not attempt to solve interrupted disk writes, cloud conflicts or every possible corrupted file.&lt;/p&gt;

&lt;p&gt;Godot's &lt;a href="https://docs.godotengine.org/en/stable/tutorials/io/saving_games.html" rel="noopener noreferrer"&gt;saving-games tutorial&lt;/a&gt; shows how to identify persistent objects and serialize selected values. It also explains JSON's limitations, including its lack of native &lt;code&gt;Vector2&lt;/code&gt; support. Treat that example as a starting point for deciding what the game needs to remember.&lt;/p&gt;

&lt;h2&gt;
  
  
  Save meaning, not incidental node structure
&lt;/h2&gt;

&lt;p&gt;Suppose an illustrative puzzle game has a door named &lt;code&gt;Door2&lt;/code&gt; in the editor. Its position in the scene tree is convenient today, but a designer may rename or regroup it tomorrow. A record keyed by &lt;code&gt;World/Room/Door2&lt;/code&gt; makes an editor organization decision part of the save contract.&lt;/p&gt;

&lt;p&gt;Instead, assign a durable game ID, such as &lt;code&gt;observatory_east_door&lt;/code&gt;. The loader maps that ID to an object in the current build. You still need a policy for a removed door, but a harmless rename no longer changes the meaning of a save.&lt;/p&gt;

&lt;p&gt;Use the same distinction for items. &lt;code&gt;item_id: "copper_key"&lt;/code&gt; is a reference to content. &lt;code&gt;display_name: "Copper Key"&lt;/code&gt; is presentation, and may change with localization. Store quantities and essential state separately from a label the player sees.&lt;/p&gt;

&lt;p&gt;Not every object needs a global identity. A short-lived particle effect probably does not need to be saved at all. Deciding what can be reconstructed is often more valuable than serializing every property.&lt;/p&gt;

&lt;h2&gt;
  
  
  A small migration with an observable result
&lt;/h2&gt;

&lt;p&gt;Here are two versions of a deliberately tiny format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"format_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"coins"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"room_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"workshop"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"format_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"wallet"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"room_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"workshop"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The migration renames a field while preserving its value. This pure Python example demonstrates the contract independently of a game engine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;migrate_save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"save must be an object"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"format_version"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"unsupported save version"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s2"&gt;"coins"&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;"wallet"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ambiguous version 1 wallet"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"wallet"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"coins"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"format_version"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"wallet"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"wallet"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"invalid wallet"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"room_id"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"workshop"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"observatory"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"unknown room"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact type checks deliberately reject Boolean values, because Python treats &lt;code&gt;bool&lt;/code&gt; as a subclass of &lt;code&gt;int&lt;/code&gt;. This is an illustrative schema, so the allowed rooms and nonnegative wallet are explicit game rules rather than universal save requirements.&lt;/p&gt;

&lt;p&gt;A version-one record with 12 coins becomes a version-two record with wallet 12. A record from a future version is rejected rather than guessed at. Local Python checks verified those outcomes, invalid-value rejection and preservation of the original input dictionary. Translate that same policy into your game's language; do not transplant Python into a GDScript project just to migrate two fields.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validate before changing the live world
&lt;/h2&gt;

&lt;p&gt;Separate reading, migration, validation and application. Parse into temporary data, migrate it, then verify the resulting identifiers and value ranges. Only after the full record is acceptable should the game replace the active session.&lt;/p&gt;

&lt;p&gt;Otherwise a loader can move the player to a new room, discover an invalid inventory halfway through, and leave a world assembled from two different saves. A useful error is “this save cannot be loaded by this build,” while keeping the current session intact.&lt;/p&gt;

&lt;p&gt;Unknown fields need a policy too. Keeping them can help round-tripping within a supported format; dropping them can simplify a tightly controlled schema. Neither choice makes an unsupported future version safe to load. A higher version number may represent changed meanings, not merely extra fields.&lt;/p&gt;

&lt;p&gt;Before any destructive conversion, retain an untouched copy. &lt;a href="https://jitsumi.com/posts/back-up-steam-game-saves" rel="noopener noreferrer"&gt;Jitsumi's guide to backing up Steam game saves&lt;/a&gt; explains why a recoverable older version is different from another synchronized copy of the same mistake.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep fixtures from released versions
&lt;/h2&gt;

&lt;p&gt;Save one small example from every format you support. Check that the oldest fixture migrates to the same current meaning as a newly created save. Include a removed item ID, an unknown room, a negative quantity and an unsupported future version.&lt;/p&gt;

&lt;p&gt;Then test the game-level result: the correct door remains open, the correct room loads, and the inventory contains the intended item. A structurally valid object is only the first half of the contract.&lt;/p&gt;

&lt;p&gt;You do not need an elaborate migration framework for a small project. A version field, a sequence of named transformations and a handful of old fixtures can be enough. Add those while the format is small, when “what did this field mean?” still has an answer.&lt;/p&gt;

</description>
      <category>jitsumi</category>
      <category>tech</category>
    </item>
    <item>
      <title>One NVIDIA Flag Is Not a Hardware Capability Model</title>
      <dc:creator>Jitsumi</dc:creator>
      <pubDate>Sun, 22 Nov 2026 00:13:00 +0000</pubDate>
      <link>https://dev.to/jitsumi/one-nvidia-flag-is-not-a-hardware-capability-model-48fk</link>
      <guid>https://dev.to/jitsumi/one-nvidia-flag-is-not-a-hardware-capability-model-48fk</guid>
      <description>&lt;p&gt;A desktop utility finds an NVIDIA GPU, so it enables every graphics control. One machine reports temperatures, another refuses a clock query, and a third loses the device after a driver reset. A single &lt;code&gt;hasNvidia&lt;/code&gt; flag cannot describe those states.&lt;/p&gt;

&lt;p&gt;Design hardware features around capabilities and query outcomes. Detect the device, attempt the supported read, preserve the reason when it fails, and enable state-changing controls only when their own requirements are satisfied. “Unknown” and “zero” must remain different values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Support belongs to a particular operation
&lt;/h2&gt;

&lt;p&gt;NVIDIA's &lt;a href="https://docs.nvidia.com/deploy/nvml-api/latest/api/group__nvmlDeviceQueries.html" rel="noopener noreferrer"&gt;NVML device-query reference&lt;/a&gt; documents operation-specific failures, including unsupported queries and devices becoming inaccessible. That is useful even if your application uses another API: successful initialisation does not establish that every subsequent field is available.&lt;/p&gt;

&lt;p&gt;Separate at least these questions in your own adapter:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Example state&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Was a compatible integration loaded?&lt;/td&gt;
&lt;td&gt;Library unavailable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Was a device found?&lt;/td&gt;
&lt;td&gt;No applicable device&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Can this reading be obtained now?&lt;/td&gt;
&lt;td&gt;Supported, denied, unsupported, temporarily unavailable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Does this operation change the device?&lt;/td&gt;
&lt;td&gt;Read-only versus state-changing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is the displayed sample fresh?&lt;/td&gt;
&lt;td&gt;Current, stale, never obtained&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Keep the original error in a diagnostic record while presenting a concise explanation to the user. “Temperature unavailable on this device” is more useful than &lt;code&gt;0 °C&lt;/code&gt;, which looks like a real measurement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use a capability object rather than a global switch
&lt;/h2&gt;

&lt;p&gt;A conceptual response for a hardware adapter might be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"deviceId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"local-device-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"temperature"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"state"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"available"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;54&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"unit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"celsius"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"sampleAgeMs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"clockControl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"state"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"unavailable"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"reason"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"not_supported"&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;This is an invented schema and sample value, not telemetry from a GPU. Its contribution is the separation of a valid reading from an unavailable command. Do not make the UI infer support from whether a numeric field happens to be null.&lt;/p&gt;

&lt;p&gt;Update these states when the adapter reports a relevant change. If a device disappears, mark its prior readings stale and stop presenting them as live. If querying fails, preserve the last known value only with its age and unavailable state clearly attached.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://docs.nvidia.com/deploy/nvml-api/latest/api/group__nvmlDeviceCommands.html" rel="noopener noreferrer"&gt;NVML command reference&lt;/a&gt; also has requirements and errors for specific operations. Read access does not imply that a write operation is supported, permitted, or appropriate. Capability discovery should not perform an experimental clock change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explain product boundaries at the same granularity
&lt;/h2&gt;

&lt;p&gt;Jitsumi makes &lt;a href="https://jitsumi.com/products/game-booster" rel="noopener noreferrer"&gt;Game Booster&lt;/a&gt;. Its documented CPU and memory monitoring differs from its NVIDIA-dependent graphics features. That is a product-level support boundary, not a claim that Game Booster uses the sample schema or NVML internally.&lt;/p&gt;

&lt;p&gt;Our &lt;a href="https://jitsumi.com/posts/check-cpu-memory-gpu-usage-windows" rel="noopener noreferrer"&gt;CPU, memory, and GPU monitoring guide&lt;/a&gt; explains the distinction for users. A developer implementing a similar interface should make each unsupported field understandable while leaving unrelated functions usable. A missing GPU temperature should not imply that the CPU reading is invalid.&lt;/p&gt;

&lt;p&gt;Separate optional tuning from monitoring in navigation, permissions, and error handling. Users investigating a missing metric should not have to enter an overclocking workflow. For ordinary troubleshooting, leave clock controls unchanged and establish which readings the hardware actually exposes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test absence as carefully as success
&lt;/h2&gt;

&lt;p&gt;Give the adapter a fake backend with independent outcomes for each feature. Test a readable temperature with unsupported clock control; successful discovery followed by device loss; a stale last sample; and a permission failure that leaves read-only functions intact.&lt;/p&gt;

&lt;p&gt;Check the rendered strings as well as the data. No failed query should turn into a zero reading. No unsupported control should look enabled because a device brand matched. No stale value should regain a live label simply because the UI rerendered.&lt;/p&gt;

&lt;p&gt;The result is a tool that can explain partial support. That is a more useful contract than declaring an entire graphics card either “supported” or “unsupported”.&lt;/p&gt;

&lt;p&gt;This article was prepared with AI assistance.&lt;/p&gt;

</description>
      <category>windows</category>
      <category>softwareengineering</category>
      <category>programming</category>
    </item>
    <item>
      <title>Finish One Room Before You Promise a Whole Game</title>
      <dc:creator>Jitsumi</dc:creator>
      <pubDate>Thu, 19 Nov 2026 06:02:00 +0000</pubDate>
      <link>https://dev.to/jitsumi/finish-one-room-before-you-promise-a-whole-game-amn</link>
      <guid>https://dev.to/jitsumi/finish-one-room-before-you-promise-a-whole-game-amn</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjvo3rpdv4hxgrr39h9bt.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjvo3rpdv4hxgrr39h9bt.webp" alt="One warmly furnished miniature room stands complete inside a much larger unfinished wooden frame." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A prototype can have movement, enemies and attractive art while still lacking the thing a player can finish. Before adding a second region or another weapon, build one room with a beginning, a meaningful decision, an ending and a reliable restart.&lt;/p&gt;

&lt;p&gt;That room is a scope tool. It makes the hidden work visible: teaching the controls, communicating failure, restoring state and handling an exit. You can then decide which parts deserve expansion instead of estimating a whole game from a character that moves around an empty scene.&lt;/p&gt;

&lt;p&gt;Godot's &lt;a href="https://docs.godotengine.org/en/stable/getting_started/first_2d_game/index.html" rel="noopener noreferrer"&gt;first 2D game tutorial&lt;/a&gt; is a useful concrete reference. Its learning outcome includes a complete game with movement, spawning and scoring, rather than an isolated movement mechanic. The one-room method below is an original planning exercise, not a claim that every successful game follows the same production process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Write a promise a player can verify
&lt;/h2&gt;

&lt;p&gt;Use a sentence describing an action and an outcome. For an illustrative project: “Redirect a moving beam to open one door, while avoiding the beam yourself.” A player can tell whether that happened.&lt;/p&gt;

&lt;p&gt;“A cozy exploration game with deep systems” cannot guide the next implementation decision nearly as well. It describes an ambition, but leaves the required interactions unbounded. Keep that ambition in your notes and give the first build a narrower promise.&lt;/p&gt;

&lt;p&gt;Choose the ending before decorating the room. If the door opens, does the player walk through it, see a completion message, or immediately restart? Any can fit the prototype. An undefined ending often becomes a pile of provisional UI and scene changes added late in the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Count the work behind one feature
&lt;/h2&gt;

&lt;p&gt;A movable mirror sounds like one object. To finish it, you may need a readable appearance, an interaction range, input handling, collision behavior, feedback, rules for invalid placement and a way to reset it. If it can rotate, the beam logic needs to account for the resulting directions.&lt;/p&gt;

&lt;p&gt;Write these dependencies before adding a second mirror type. They are not evidence that the idea is bad. They are the actual cost of letting someone use it without your explanation.&lt;/p&gt;

&lt;p&gt;A small scope ledger makes the tradeoffs tangible:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Proposed addition&lt;/th&gt;
&lt;th&gt;Work it creates&lt;/th&gt;
&lt;th&gt;First-room decision&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A second mirror colour&lt;/td&gt;
&lt;td&gt;New rule, teaching and feedback&lt;/td&gt;
&lt;td&gt;Defer until one mirror is understandable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Persistent inventory&lt;/td&gt;
&lt;td&gt;Pickup, UI, save and load behavior&lt;/td&gt;
&lt;td&gt;Remove; the room supplies its tools&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Random room layout&lt;/td&gt;
&lt;td&gt;Generation rules and failure cases&lt;/td&gt;
&lt;td&gt;Use one authored layout&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Restart button&lt;/td&gt;
&lt;td&gt;Reset positions, timers and interactions&lt;/td&gt;
&lt;td&gt;Keep; necessary to repeat the task&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These choices fit this example. A different game's central promise might require inventory or generation from the start. Cut supporting complexity before cutting the mechanic you actually want to investigate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate necessary quality from extra content
&lt;/h2&gt;

&lt;p&gt;Placeholder art can be appropriate for a beam puzzle, but an unreadable beam is not a neutral placeholder. If players cannot distinguish the hazard from the background, the prototype is testing the wrong problem.&lt;/p&gt;

&lt;p&gt;Identify the minimum presentation that communicates the rules: interaction highlights, the beam's path, a clear door state and feedback when a mirror moves. Those belong in the room even if decorative scenery waits.&lt;/p&gt;

&lt;p&gt;The same applies to controls. A prototype that requires the developer to explain which key works has not yet tested whether a player can begin. Provide the necessary instruction in the game, then observe what someone unfamiliar with it does.&lt;/p&gt;

&lt;p&gt;You can deliberately omit polish that does not affect the current question. A custom animated title sequence is unlikely to establish whether the mirror interaction is understandable. A visible restart option probably will.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make reset a first-class behavior
&lt;/h2&gt;

&lt;p&gt;Write down the initial state: mirror position, beam direction, player location, door state and elapsed time. After failure or completion, return to that same state. Do not reset only the objects you happened to notice during one playthrough.&lt;/p&gt;

&lt;p&gt;Godot's &lt;a href="https://docs.godotengine.org/en/stable/tutorials/best_practices/scene_organization.html" rel="noopener noreferrer"&gt;scene organization guide&lt;/a&gt; explains why scenes with focused responsibilities and limited external dependencies are easier to reuse. For a room prototype, a parent scene that owns the room's initial state can provide a clear place to coordinate reset.&lt;/p&gt;

&lt;p&gt;Keep a copy of a known playable build before structural changes. Large source artwork and recordings are broader project files that version control may not cover. Confirm you can restore those assets rather than counting a sync folder as the whole plan; &lt;a href="https://jitsumi.com/posts/back-up-steam-game-saves" rel="noopener noreferrer"&gt;Jitsumi's guide to backing up Steam game saves&lt;/a&gt; shows the same copy-then-check habit for save data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Expand from a completed loop
&lt;/h2&gt;

&lt;p&gt;Give the room to someone without narrating the solution. Note whether they recognize the goal, discover the interaction, recover from failure and understand completion. One participant's account can expose a concrete issue; it does not establish market demand.&lt;/p&gt;

&lt;p&gt;Only then propose room two. Name what it adds: a new combination of the existing rule, a harder timing requirement, or a genuinely new mechanic. If the new room mostly repeats unfinished infrastructure work, finish that infrastructure first.&lt;/p&gt;

&lt;p&gt;A complete room gives you something more useful than a larger feature list: a bounded experience you can inspect, repeat and revise. Expansion becomes a choice grounded in an actual playable loop.&lt;/p&gt;

</description>
      <category>jitsumi</category>
      <category>tech</category>
    </item>
    <item>
      <title>Pixel Art Needs an Integer Scale, Not Just Nearest Filtering</title>
      <dc:creator>Jitsumi</dc:creator>
      <pubDate>Wed, 11 Nov 2026 23:32:00 +0000</pubDate>
      <link>https://dev.to/jitsumi/pixel-art-needs-an-integer-scale-not-just-nearest-filtering-2fa7</link>
      <guid>https://dev.to/jitsumi/pixel-art-needs-an-integer-scale-not-just-nearest-filtering-2fa7</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4rhmi4vehf6ffmjvg7uz.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4rhmi4vehf6ffmjvg7uz.webp" alt="A cobalt, turquoise and orange kingfisher is built from square ceramic mosaic pieces." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nearest-neighbor filtering can keep a sprite sharp while its pixels still look uneven. A one-pixel line may become three display pixels wide in one place and four in another. The image is crisp, but its grid no longer has a consistent rhythm.&lt;/p&gt;

&lt;p&gt;For a deliberately low-resolution 2D game, choose an internal canvas size, enlarge it by a whole-number factor, and accept unused space when the window does not fit that grid. Filtering and scaling solve related but different problems.&lt;/p&gt;

&lt;p&gt;Godot's &lt;a href="https://docs.godotengine.org/en/stable/tutorials/rendering/multiple_resolutions.html" rel="noopener noreferrer"&gt;multiple-resolutions documentation&lt;/a&gt; explains its stretch modes and integer scaling option. The arithmetic here helps you choose the underlying resolution before changing settings at random.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two decisions sit between the sprite and the screen
&lt;/h2&gt;

&lt;p&gt;Filtering decides how a texture is sampled. Linear filtering blends neighboring texels, which can soften a small pixel-art sprite. Nearest sampling chooses a texel without that blend.&lt;/p&gt;

&lt;p&gt;Scaling decides where source pixels land in the output grid. If each source pixel becomes a 4-by-4 block, the enlarged grid is regular. At a scale of 3.75, display pixels cannot represent every block as exactly 3.75 physical pixels. Rasterization must distribute the available pixels somehow.&lt;/p&gt;

&lt;p&gt;That is why “turn off filtering” is an incomplete answer to inconsistent pixel widths. It addresses blending, but it cannot make a fractional grid divide evenly.&lt;/p&gt;

&lt;p&gt;The choice is artistic as well as technical. A game with high-resolution UI over low-resolution scenery may intentionally use multiple rendering layers. The simplest whole-canvas approach is useful when the entire world should share one pixel grid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calculate the largest fitting factor
&lt;/h2&gt;

&lt;p&gt;For an illustrative internal resolution of 320 by 180, a 1280-by-720 content area fits a factor of four exactly. A 1366-by-768 area also fits only four times: the world occupies 1280 by 720, leaving 86 horizontal and 48 vertical pixels outside it.&lt;/p&gt;

&lt;p&gt;Centering distributes that remainder as 43 pixels on either side and 24 above and below. That unused space is the cost of preserving the grid. Stretching to fill the entire area uses fractional factors and changes the promise.&lt;/p&gt;

&lt;p&gt;The fitting rule is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;integer_fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base_w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;available_w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;available_h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base_w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;available_w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;available_h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dimensions must be positive"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;factor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;available_w&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;base_w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;available_h&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;base_h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"available area is smaller than the base canvas"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base_w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_h&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the actual drawable content area, which may differ from the operating system's advertised display resolution. A window border, display scaling or another enclosing surface can change the pixels available to the game.&lt;/p&gt;

&lt;p&gt;If the area is smaller than your base canvas, this function refuses the request. Your product still needs a policy: enforce a minimum size, select a smaller canvas or permit a documented downscale. A whole-number enlargement setting cannot solve a window that is already too small.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose Godot's stretch behavior deliberately
&lt;/h2&gt;

&lt;p&gt;For a low-resolution world, Godot's &lt;code&gt;viewport&lt;/code&gt; stretch mode renders at the base viewport size before scaling the result. Combine the appropriate aspect policy with integer scale mode where supported by your target Godot version. Use nearest texture filtering for pixel-art elements that require it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;canvas_items&lt;/code&gt; serves a different goal: 2D elements are rendered at the target resolution while their canvas transforms adapt. It can be appropriate for high-resolution content, but it does not automatically make the entire rendered world one low-resolution image.&lt;/p&gt;

&lt;p&gt;Do not apply these settings indiscriminately to all text. A low-resolution font may suit the game's visual design, while a separate high-resolution interface can improve readability. If you combine them, test the boundary rather than assuming the world and UI share identical scaling requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  A correct scale can still show uneven motion
&lt;/h2&gt;

&lt;p&gt;Watch a sprite and the camera move slowly. Fractional object positions, camera transforms and rotation can affect how pixel art is sampled. Integer enlargement preserves the final canvas grid; it does not guarantee that every moving shape is aligned to that grid internally.&lt;/p&gt;

&lt;p&gt;Use a test pattern with alternating one-pixel stripes, a simple sprite and a slow camera pan. Inspect still frames and motion separately. If every still frame has consistent block sizes but movement appears to shimmer, investigate internal positioning and camera behavior.&lt;/p&gt;

&lt;p&gt;When sharing the evidence, avoid a resized preview as your only record. Save a direct capture of your development build at its original dimensions, record the viewport settings, and note any later scaling. A chat application's thumbnail can hide the uneven grid you want someone else to inspect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the awkward sizes
&lt;/h2&gt;

&lt;p&gt;Try a window that exactly matches a scale factor, one just below the next factor, and a narrow aspect ratio. Confirm where unused space appears and whether interface controls remain usable. Include the smallest supported content area in your acceptance check.&lt;/p&gt;

&lt;p&gt;The right result may have borders. Those borders are preferable when they preserve the visual contract you chose. If filling every display matters more, accept fractional scaling deliberately and assess how it looks; do not expect a texture-filter setting to make both choices identical.&lt;/p&gt;

&lt;p&gt;Further reading from this publisher: &lt;a href="https://jitsumi.com/" rel="noopener noreferrer"&gt;Jitsumi's practical guides to games and developer tools&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>jitsumi</category>
      <category>tech</category>
    </item>
    <item>
      <title>prefers-reduced-motion Needs a Replacement, Not Just a Switch</title>
      <dc:creator>Jitsumi</dc:creator>
      <pubDate>Sat, 07 Nov 2026 23:39:00 +0000</pubDate>
      <link>https://dev.to/jitsumi/prefers-reduced-motion-needs-a-replacement-not-just-a-switch-1kdd</link>
      <guid>https://dev.to/jitsumi/prefers-reduced-motion-needs-a-replacement-not-just-a-switch-1kdd</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmq10x8wmd38amyuiuqqb.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmq10x8wmd38amyuiuqqb.webp" alt="A browser captured with reduced motion emulation shows a completed upload notice and computed animation-name none." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A panel slides into view to show that an action succeeded. When a user prefers reduced motion, removing the slide is sensible. Removing the only sign of success is not. An accessible alternative preserves the information while changing how it arrives.&lt;/p&gt;

&lt;p&gt;Treat &lt;code&gt;prefers-reduced-motion&lt;/code&gt; as a design input. Identify what each animation communicates, then decide whether that meaning can be carried by an immediate state change, a short opacity transition, a label, or a persistent status message. A universal rule that sets every duration to nearly zero skips that work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Begin with a calm baseline
&lt;/h2&gt;

&lt;p&gt;For a small expandable panel, the non-animated state can be the default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.notice&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-reduced-motion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;no-preference&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.notice&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;data-entering&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"true"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;notice-enter&lt;/span&gt; &lt;span class="m"&gt;180ms&lt;/span&gt; &lt;span class="nb"&gt;ease-out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;notice-enter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;from&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;.75rem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;to&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&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;This snippet assumes the application sets &lt;code&gt;data-entering&lt;/code&gt; when showing a notice. The notice remains present and readable without the animation. The duration is an illustrative design choice, not a medical threshold or accessibility guarantee.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3.org/TR/mediaqueries-5/#prefers-reduced-motion" rel="noopener noreferrer"&gt;Media Queries Level 5 defines the preference&lt;/a&gt; as a request to minimise the amount of non-essential motion. &lt;code&gt;no-preference&lt;/code&gt; does not mean the user affirmatively requested animation. It means the query does not detect a reduced-motion preference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate movement from information
&lt;/h2&gt;

&lt;p&gt;List the purpose of a particular effect in an ordinary sentence. “The item moves into the basket so people understand where it went” is specific enough to evaluate. In reduced mode, a basket count that changes immediately and a short status message can carry that outcome without the travelling object.&lt;/p&gt;

&lt;p&gt;An activity spinner has a different purpose: it signals that work is unfinished. Removing all animation may leave an ambiguous empty space. A persistent “Uploading…” label, followed by an explicit completion or failure state, can preserve the information. For a measurable operation, a progress value may be more useful than decorative rotation.&lt;/p&gt;

&lt;p&gt;The same reasoning applies to navigation transitions. If the outgoing screen fades away before the incoming heading appears, consider whether the transition helps orientation or delays access. Reduced mode can switch immediately and place focus appropriately. The focus decision remains necessary even when the animation disappears.&lt;/p&gt;

&lt;h2&gt;
  
  
  Audit motion outside keyframes
&lt;/h2&gt;

&lt;p&gt;CSS animations are only part of the inventory. Smooth scrolling, large hover transforms, parallax effects, animated SVG, video backgrounds, and JavaScript-driven motion can all need review. Changing an &lt;code&gt;animation-duration&lt;/code&gt; rule does not alter a &lt;code&gt;requestAnimationFrame&lt;/code&gt; loop that directly updates transforms.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion" rel="noopener noreferrer"&gt;MDN's media-feature reference&lt;/a&gt; explains using the preference in CSS and links to operating-system settings. For JavaScript behaviour, use &lt;code&gt;matchMedia('(prefers-reduced-motion: reduce)')&lt;/code&gt; and respond to its current &lt;code&gt;matches&lt;/code&gt; value. If the interface remains open while the preference changes, listen for the media query's &lt;code&gt;change&lt;/code&gt; event and adjust ongoing effects.&lt;/p&gt;

&lt;p&gt;Clean up that listener when the owning component is disposed. Otherwise, a preference intended to simplify the experience can expose lifecycle bugs in the application's animation layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid brittle global cancellation
&lt;/h2&gt;

&lt;p&gt;A global near-zero animation rule can affect code waiting for an animation to end. It can also leave elements in a state that was designed to be temporary. An entrance effect that begins with hidden content needs a readable final state regardless of whether the effect runs.&lt;/p&gt;

&lt;p&gt;This is one reason to make application state independent of animation completion whenever possible. The data says the panel is open; the animation decorates the transition. If the panel becomes open only because an event handler for the animation runs, reduced mode, interrupted transitions, or removed elements may reveal the coupling.&lt;/p&gt;

&lt;p&gt;Some effects can be simplified locally. Others should be removed completely. A small colour change and a large zoom are not interchangeable experiences, and “less motion” is not a single duration value. Review the actual spatial movement and the user's task.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the alternate path as a real mode
&lt;/h2&gt;

&lt;p&gt;Enable reduced motion in the operating system or browser's emulation tools, then complete the interface's main tasks. Check that expanded content appears, progress remains understandable, and success or failure remains visible. Change the preference while an effect is active if the application supports live changes.&lt;/p&gt;

&lt;p&gt;Also use the interface with a keyboard. An animated scroll may have hidden a focus-placement mistake by making the destination visually obvious; the immediate transition can expose it. The answer is to fix orientation, not restore compulsory movement.&lt;/p&gt;

&lt;p&gt;The finished mode should feel deliberate. The same outcomes happen, the same information remains available, and movement no longer carries a message that nothing else explains.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Published by &lt;a href="https://jitsumi.com" rel="noopener noreferrer"&gt;Jitsumi&lt;/a&gt;, covering useful software and developer decisions.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>jitsumi</category>
      <category>tech</category>
    </item>
    <item>
      <title>Stop Stale Editors Overwriting Changes with If-Match</title>
      <dc:creator>Jitsumi</dc:creator>
      <pubDate>Fri, 06 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/jitsumi/stop-stale-editors-overwriting-changes-with-if-match-5a0l</link>
      <guid>https://dev.to/jitsumi/stop-stale-editors-overwriting-changes-with-if-match-5a0l</guid>
      <description>&lt;p&gt;Two people open the same settings page. One changes the title; the other saves a description a minute later. Both receive a successful response, but the second save restores the old title.&lt;/p&gt;

&lt;p&gt;The second person did not deliberately undo anything. Their editor submitted an old copy of the document. If your API accepts every replacement unconditionally, the most recent request wins even when it contains older information.&lt;/p&gt;

&lt;p&gt;For an HTTP API, a useful defence is a &lt;strong&gt;strong ETag paired with &lt;code&gt;If-Match&lt;/code&gt;&lt;/strong&gt;. The client sends the version it edited; the server applies the change only if that version is still current. A mismatch normally produces &lt;code&gt;412 Precondition Failed&lt;/code&gt;, giving the editor a chance to reconcile instead of silently overwriting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turn the version into a save condition
&lt;/h2&gt;

&lt;p&gt;An illustrative read might return:&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="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;application/json&lt;/span&gt;
&lt;span class="na"&gt;ETag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"settings-17"&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Release notes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Weekly changes"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep the quoted validator with the loaded document. When saving, send it unchanged:&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="nf"&gt;PUT&lt;/span&gt; &lt;span class="nn"&gt;/settings&lt;/span&gt; &lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt;
&lt;span class="na"&gt;Content-Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;application/json&lt;/span&gt;
&lt;span class="na"&gt;If-Match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"settings-17"&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Release notes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Changes every Friday"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If another editor has already produced version 18, the condition is false. &lt;a href="https://www.rfc-editor.org/rfc/rfc9110.html#section-13.1.1" rel="noopener noreferrer"&gt;RFC 9110's &lt;code&gt;If-Match&lt;/code&gt; rules&lt;/a&gt; define this conditional request behaviour. The header uses strong comparison: a weak tag such as &lt;code&gt;W/"settings-17"&lt;/code&gt; cannot satisfy it. See Mozilla's &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-Match" rel="noopener noreferrer"&gt;&lt;code&gt;If-Match&lt;/code&gt; reference&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Treat the ETag as an opaque value. Clients should not increment its number or reconstruct it from a timestamp. The server owns its meaning, including which representation it identifies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reproduce the conflict without an HTTP server
&lt;/h2&gt;

&lt;p&gt;This small model demonstrates the save rule. Save it as &lt;code&gt;conditional-save.mjs&lt;/code&gt; and run &lt;code&gt;node conditional-save.mjs&lt;/code&gt; with a current Node.js release. It uses only the built-in assertion module:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;assert&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;node:assert/strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Release notes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Weekly changes&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;tag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`"settings-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;version&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;read&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;document&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;etag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;replacement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ifMatch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// No await between comparing and updating this in-memory model.&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ifMatch&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;412&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;replacement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;etag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&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;alice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;read&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;ben&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;alice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Engineering release notes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;alice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;alice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;etag&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;ben&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Changes every Friday&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ben&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ben&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;etag&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;412&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Engineering release notes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Weekly changes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Stale save rejected; the first edit remains.&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;Ben's description is still in his local editor. It was never accepted by the server. That is the point at which the interface should offer a comparison, not announce that everything has been saved.&lt;/p&gt;

&lt;h2&gt;
  
  
  The database must enforce the same boundary
&lt;/h2&gt;

&lt;p&gt;A server implementation can still lose updates if it checks the version, yields to another request, and later writes without a condition. Comparing the tag in one database query and performing an unconditional update in another recreates the race.&lt;/p&gt;

&lt;p&gt;For a versioned row, the core operation might be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;version&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;expected_version&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Interpret the affected-row count and distinguish a missing resource from a stale version according to your API contract. Authenticate and authorise the caller independently. For an ETag representing several rows, the transaction must cover every change contributing to that representation.&lt;/p&gt;

&lt;p&gt;This SQL is an implementation sketch, not a complete HTTP validator parser. A production endpoint must also handle required-header policy, validation, representation variants and its database's transaction behaviour.&lt;/p&gt;

&lt;h2&gt;
  
  
  A conflict is different from an uncertain retry
&lt;/h2&gt;

&lt;p&gt;On 412, keep the unsaved changes, fetch the latest document and show what changed. Automatically replacing the ETag and resubmitting the old whole document defeats the protection. A field-by-field merge can help, but overlapping edits still need a deliberate decision.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;If-Match: *&lt;/code&gt; is not equivalent to a version-specific tag: it checks for an existing representation, not whether the editor saw the current one.&lt;/p&gt;

&lt;p&gt;Also separate concurrency from transport uncertainty. If a response disappears after a successful save, the caller needs to discover the outcome; retry design is a separate concern. Jitsumi's explanation of &lt;a href="https://jitsumi.com/posts/api-idempotency-retry-requests-without-duplicates" rel="noopener noreferrer"&gt;API idempotency and uncertain retries&lt;/a&gt; works through that boundary.&lt;/p&gt;

&lt;p&gt;For caching, the related validator question is usually whether a stored representation can be reused. Jitsumi's &lt;a href="https://jitsumi.com/posts/cache-control-no-cache-vs-no-store-etag" rel="noopener noreferrer"&gt;ETag and Cache-Control example&lt;/a&gt; covers that read path. The save path here asks a different question: &lt;strong&gt;is this still the version the editor is entitled to replace?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This article was prepared with AI assistance.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>http</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Your SQL Pagination Can Repeat Rows. A Cursor Fixes Only Part of It.</title>
      <dc:creator>Jitsumi</dc:creator>
      <pubDate>Thu, 05 Nov 2026 04:49:00 +0000</pubDate>
      <link>https://dev.to/jitsumi/your-sql-pagination-can-repeat-rows-a-cursor-fixes-only-part-of-it-3o2o</link>
      <guid>https://dev.to/jitsumi/your-sql-pagination-can-repeat-rows-a-cursor-fixes-only-part-of-it-3o2o</guid>
      <description>&lt;p&gt;Page one looks right. You click &lt;strong&gt;Load more&lt;/strong&gt;, and the last item appears again. Someone deletes a record, and now an item disappears between pages instead.&lt;/p&gt;

&lt;p&gt;This can happen with a perfectly valid &lt;code&gt;ORDER BY&lt;/code&gt;. The problem is that &lt;code&gt;OFFSET 20&lt;/code&gt; skips twenty rows in the result &lt;strong&gt;as it exists now&lt;/strong&gt;, rather than continuing after the twenty rows you already saw.&lt;/p&gt;

&lt;p&gt;For a changing feed, keyset pagination gives you a better boundary: continue after this exact pair of sort values. But it still reads changing data. If you need an export of everything that existed at a particular moment, a cursor alone cannot provide that guarantee.&lt;/p&gt;

&lt;p&gt;Let's reproduce both the fix and its limits with six rows, SQLite and a small Node.js script.&lt;/p&gt;

&lt;h2&gt;
  
  
  A page number remembers a position
&lt;/h2&gt;

&lt;p&gt;Suppose an activity feed sorts newest first. These are illustrative integer timestamps, with larger numbers meaning later events:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;&lt;code&gt;created_at&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The query is explicit about the order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;OFFSET&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It returns IDs &lt;strong&gt;6, 5&lt;/strong&gt;. The ID breaks the tie between the two events at time 400. Without a unique order, you have an additional problem: the database has no obligation to keep tied rows in the order you happened to observe. PostgreSQL's &lt;a href="https://www.postgresql.org/docs/current/queries-limit.html" rel="noopener noreferrer"&gt;LIMIT and OFFSET documentation&lt;/a&gt; calls out that requirement.&lt;/p&gt;

&lt;p&gt;Now insert ID 7 at time 600. The ordered IDs become &lt;strong&gt;7, 6, 5, 4, 3, 2, 1&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Your next request uses &lt;code&gt;OFFSET 2&lt;/code&gt;. It skips 7 and 6, then returns &lt;strong&gt;5, 4&lt;/strong&gt;. ID 5 repeats because the insertion shifted its position. The query did exactly what you asked.&lt;/p&gt;

&lt;p&gt;Deletion creates the opposite failure. Starting from the original six rows, delete ID 6 after fetching page one. The list becomes &lt;strong&gt;5, 4, 3, 2, 1&lt;/strong&gt;. Skipping two now returns &lt;strong&gt;3, 2&lt;/strong&gt;, so you never see ID 4.&lt;/p&gt;

&lt;p&gt;These are separate reads with a change between them, not a claim that one SQL statement sees half an insertion.&lt;/p&gt;

&lt;h2&gt;
  
  
  A cursor remembers a boundary
&lt;/h2&gt;

&lt;p&gt;After page one, keep its last row's sort values: &lt;code&gt;(created_at=400, id=5)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For the next page, ask for rows below that pair:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;created_at&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bind &lt;code&gt;400&lt;/code&gt; and &lt;code&gt;5&lt;/code&gt; to the placeholders. The query returns &lt;strong&gt;4, 3&lt;/strong&gt;, whether ID 7 was inserted above the boundary or ID 6 was deleted there.&lt;/p&gt;

&lt;p&gt;This is keyset pagination, often exposed by an API as a cursor. SQLite supports &lt;a href="https://sqlite.org/rowvalue.html" rel="noopener noreferrer"&gt;row-value comparisons&lt;/a&gt;, which compare components from left to right. With both columns sorted descending, &lt;code&gt;&amp;lt;&lt;/code&gt; asks for the next, lower pair. An all-ascending version uses &lt;code&gt;&amp;gt;&lt;/code&gt;; mixed sort directions need a predicate that follows each column's direction.&lt;/p&gt;

&lt;p&gt;ID 4 belongs on the next page because its timestamp equals 400 and its ID is below 5. A timestamp-only condition, &lt;code&gt;created_at &amp;lt; 400&lt;/code&gt;, skips it. Using &lt;code&gt;&amp;lt;= 400&lt;/code&gt; instead also admits ID 5 again. The cursor must carry the tie-breaker too.&lt;/p&gt;

&lt;p&gt;The boundary values are sufficient even if the row they came from is later deleted. You do not need to look that row up again to reconstruct its timestamp.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the failure and the fix
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;pagination-demo.mjs&lt;/code&gt;. It creates an in-memory database, so it never opens or changes an application database. It needs Node.js with the built-in &lt;code&gt;node:sqlite&lt;/code&gt; module; Node.js 24 and 26 provide it without installing a package. The API's stability designation depends on the release; see the &lt;a href="https://nodejs.org/download/release/v26.6.0/docs/api/sqlite.html" rel="noopener noreferrer"&gt;documentation for the version used here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The synchronous database API keeps this disposable example short. It is not a recommendation to block a busy web server's event loop.&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;assert&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;node:assert/strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;DatabaseSync&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;node:sqlite&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;db&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;DatabaseSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;:memory:&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;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&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;ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
  CREATE TABLE events (
    id INTEGER PRIMARY KEY,
    created_at INTEGER NOT NULL
  );
  CREATE INDEX events_feed ON events(created_at DESC, id DESC);
`&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;insert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;INSERT INTO events VALUES (?, ?)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DELETE FROM events&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;time&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;]])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;time&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;offsetPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;offset&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="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
    SELECT id, created_at FROM events
    ORDER BY created_at DESC, id DESC LIMIT ? OFFSET ?
  `&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cursor&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="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
    SELECT id, created_at FROM events
    WHERE (created_at, id) &amp;lt; (?, ?)
    ORDER BY created_at DESC, id DESC LIMIT ?
  `&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;created_at&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deepEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;reset&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;first&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;offsetPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&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;cursor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Page 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="nx"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Insert / OFFSET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;offsetPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Insert / cursor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DELETE FROM events WHERE id = 6&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Delete / OFFSET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;offsetPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Delete / cursor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="nf"&gt;reset&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;timestampOnly&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
    SELECT id, created_at FROM events WHERE created_at &amp;lt; ?
    ORDER BY created_at DESC, id DESC LIMIT ?
  `&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;created_at&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Timestamp-only cursor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;timestampOnly&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Composite cursor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;UPDATE events SET created_at = 550 WHERE id = 4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Moved unseen row / cursor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;350&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Backdated insert / cursor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;All assertions passed.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&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;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node pagination-demo.mjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Page 1: 6, 5
Insert / OFFSET: 5, 4
Insert / cursor: 4, 3
Delete / OFFSET: 3, 2
Delete / cursor: 4, 3
Timestamp-only cursor: 3, 2
Composite cursor: 4, 3
Moved unseen row / cursor: 3, 2
Backdated insert / cursor: 4, 7
All assertions passed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example was executed on Windows with &lt;strong&gt;Node.js 26.6.0 and SQLite 3.53.3 on 5 November 2026&lt;/strong&gt;. The assertions verify returned rows under controlled changes; this is not a throughput benchmark or a test of a deployed API.&lt;/p&gt;

&lt;p&gt;Notice the last two cases. They explain why switching to cursors should also change how you describe the endpoint's behaviour.&lt;/p&gt;

&lt;h2&gt;
  
  
  A cursor does not freeze the feed
&lt;/h2&gt;

&lt;p&gt;After page one, the cursor still means “below &lt;code&gt;(400, 5)&lt;/code&gt;”. It does not mean “the remaining rows from my first request”.&lt;/p&gt;

&lt;p&gt;If unseen ID 4 changes its timestamp from 400 to 550, it moves above the boundary. The next page returns &lt;strong&gt;3, 2&lt;/strong&gt;. The cursor cannot tell that you have never seen ID 4. Similarly, an already displayed row can reappear if its sort key moves below the boundary.&lt;/p&gt;

&lt;p&gt;A newly inserted row can also appear halfway through the traversal. The demo inserts ID 7 at time 350. It is below the cursor, so the next page returns &lt;strong&gt;4, 7&lt;/strong&gt;, even though ID 7 did not exist when you fetched page one.&lt;/p&gt;

&lt;p&gt;That behaviour can be appropriate for a live feed. It is a poor surprise in a report labelled “all records as of 09:00”.&lt;/p&gt;

&lt;p&gt;Prefer immutable ordering values when you want a predictable forward traversal. A creation sequence or a creation timestamp plus a unique ID may fit; a mutable popularity score or &lt;code&gt;updated_at&lt;/code&gt; usually needs a more deliberate product contract. Even immutable sort keys do not prevent deletions or changes to which rows match the filters.&lt;/p&gt;

&lt;p&gt;For a consistent export, use a database-supported consistent read or materialise the required results in a background job. SQLite's &lt;a href="https://www.sqlite.org/isolation.html" rel="noopener noreferrer"&gt;isolation documentation&lt;/a&gt; explains how a read transaction in WAL mode retains its snapshot while other connections commit changes. Separate HTTP requests do not automatically share that transaction.&lt;/p&gt;

&lt;p&gt;Holding a database transaction open while a person browses several pages has operational costs. An export job can own a bounded consistent read and produce a file; an interactive feed can promise forward continuation over current data. Choose the guarantee you actually need.&lt;/p&gt;

&lt;p&gt;Also distinguish freezing membership from freezing values. Saving a list of matching IDs preserves which records were selected, but looking those IDs up later can still return edited values or find deleted rows. A historical report needs the corresponding historical values too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the query, index and API agree
&lt;/h2&gt;

&lt;p&gt;For the demo's query, the index follows the ordering columns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;events_feed&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An appropriate index lets the database seek towards the boundary instead of discarding a growing prefix. That does not make every cursor query fast: extra filters, joins and the chosen plan still matter. SQLite's &lt;a href="https://sqlite.org/queryplanner.html" rel="noopener noreferrer"&gt;query-planning guide&lt;/a&gt; explains how indexes can support searching and ordering together. Inspect your actual query plan and representative data before making a performance claim.&lt;/p&gt;

&lt;p&gt;For a tenant-scoped feed, apply the tenant restriction on &lt;strong&gt;every&lt;/strong&gt; page. An index starting with the tenant equality column, followed by the sort columns, is a candidate to evaluate. A cursor supplies a position; it never grants permission to read a tenant's records.&lt;/p&gt;

&lt;p&gt;When turning the SQL into an HTTP endpoint, keep these details explicit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep the full ordering tuple.&lt;/strong&gt; Preserve timestamp precision and exact IDs through the database driver, cursor encoder and decoder. For large integer IDs in JavaScript, Jitsumi's guide to &lt;a href="https://jitsumi.com/posts/javascript-large-json-ids-preserve-precision" rel="noopener noreferrer"&gt;preserving IDs across JSON boundaries&lt;/a&gt; covers the numeric precision trap. The demo's small integers avoid that separate issue.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the same query context.&lt;/strong&gt; Validate the cursor's shape, version, filter context and sort order. Reject a cursor for a different search instead of silently interpreting it under new rules. A server-issued opaque token can represent that context; base64 encoding alone does not make a token trustworthy. Reapply current authorisation regardless.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bind values and bound the page size.&lt;/strong&gt; Use parameters for cursor values, as the example does. Validate an integer page size against a server limit. Select sorting from an allowlist rather than inserting arbitrary client input into SQL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Define null handling.&lt;/strong&gt; This example makes &lt;code&gt;created_at&lt;/code&gt; non-null. Nullable sort columns need an explicit ordering and continuation rule; a tuple comparison involving null does not behave like an ordinary numeric comparison.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To report whether another page is available, request &lt;code&gt;page_size + 1&lt;/code&gt; rows. Return only the first &lt;code&gt;page_size&lt;/code&gt;, and construct the next cursor from the &lt;strong&gt;last returned row&lt;/strong&gt;, not the extra look-ahead row. Otherwise you skip the look-ahead item. The extra row tells you that more data existed when that query ran; it cannot promise that it will still exist on the next request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep OFFSET when its trade-off fits
&lt;/h2&gt;

&lt;p&gt;Offset pagination remains useful for small lists and interfaces that need direct page-number navigation. A cursor cannot jump to page 50 without a known boundary or another lookup strategy.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Reader's task&lt;/th&gt;
&lt;th&gt;Approach to consider&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Browse a small table with numbered pages&lt;/td&gt;
&lt;td&gt;OFFSET with a unique order; accept movement between reads&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Keep loading older items in a changing feed&lt;/td&gt;
&lt;td&gt;Keyset cursor with stable sort keys and matching filters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Produce a report of one consistent dataset&lt;/td&gt;
&lt;td&gt;Consistent read or materialised export; paginate that fixed result if needed&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Before shipping, make the test uncomfortable: give two rows the same timestamp, insert above the boundary, delete a previously displayed row, and change an ordering value. Check exact IDs across successive pages.&lt;/p&gt;

&lt;p&gt;The useful promise for a cursor endpoint is precise: continue below this boundary under these filters. If the product promises a frozen dataset, build that guarantee separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;Documentation checked on 5 November 2026.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://sqlite.org/rowvalue.html" rel="noopener noreferrer"&gt;SQLite: row values and scrolling-window queries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.postgresql.org/docs/current/queries-limit.html" rel="noopener noreferrer"&gt;PostgreSQL: LIMIT, OFFSET and deterministic ordering&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sqlite.org/queryplanner.html" rel="noopener noreferrer"&gt;SQLite: query planning and multi-column indexes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.sqlite.org/isolation.html" rel="noopener noreferrer"&gt;SQLite: isolation and snapshots&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/download/release/v26.6.0/docs/api/sqlite.html" rel="noopener noreferrer"&gt;Node.js 26.6.0: built-in SQLite API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>jitsumi</category>
      <category>tech</category>
    </item>
    <item>
      <title>Promise.all Doesn't Limit Concurrency. Here's a Small Pool That Does.</title>
      <dc:creator>Jitsumi</dc:creator>
      <pubDate>Wed, 04 Nov 2026 16:24:00 +0000</pubDate>
      <link>https://dev.to/jitsumi/promiseall-doesnt-limit-concurrency-heres-a-small-pool-that-does-33cn</link>
      <guid>https://dev.to/jitsumi/promiseall-doesnt-limit-concurrency-heres-a-small-pool-that-does-33cn</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq6hnjuni3wifv88wre1o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq6hnjuni3wifv88wre1o.png" alt="A conceptual queue of terracotta task tiles passing through a gate with three channels, illustrating bounded concurrency." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Concept illustration: three occupied slots, with the remaining work waiting.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A script fetches a handful of records without trouble. Then someone gives it a thousand IDs, and the same code produces a burst of requests, timeouts and retries.&lt;/p&gt;

&lt;p&gt;The suspicious line often looks perfectly reasonable:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;records&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;id&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;fetchRecord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no concurrency limit here. &lt;code&gt;map()&lt;/code&gt; invokes the callback across the array before &lt;code&gt;Promise.all()&lt;/code&gt; waits for the resulting promises. If &lt;code&gt;fetchRecord()&lt;/code&gt; starts a request when called, the requests have already been started.&lt;/p&gt;

&lt;p&gt;To cap active work, control &lt;strong&gt;when you call the function that starts it&lt;/strong&gt;. This article builds a small pool for a finite array, preserves result order, and makes failures explicit. It is useful for independent I/O tasks such as fetching records or processing files. It does not add CPU parallelism.&lt;/p&gt;

&lt;h2&gt;
  
  
  The difference between a promise and a job
&lt;/h2&gt;

&lt;p&gt;Consider these two values:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;alreadyStarted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fetchRecord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&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;startLater&lt;/span&gt; &lt;span class="o"&gt;=&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;fetchRecord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first is the result of calling the function. The second gives a scheduler the ability to decide when to call it. Putting &lt;code&gt;alreadyStarted&lt;/code&gt; into a queue cannot retroactively postpone the request.&lt;/p&gt;

&lt;p&gt;This is why wrapping a promise in another function is too late:&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;// Still starts every request during map():&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promises&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;id&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;fetchRecord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&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;jobs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;promises&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep the input as data instead. Give the pool an ID and a callback; let the pool invoke that callback only when a slot is free. MDN documents &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;&lt;code&gt;Array.prototype.map()&lt;/code&gt;&lt;/a&gt; as building a new array from callback results. It provides no admission-control mechanism for asynchronous work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose the failure policy before writing the pool
&lt;/h2&gt;

&lt;p&gt;For a batch of independent records, one failed record should not hide the outcomes of the others. The pool below returns one of two result shapes at each input position:&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="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fulfilled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;record&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rejected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It continues processing after a task fails and resolves after every task settles. That is a deliberate policy, suitable when you want a complete batch report. It would be the wrong default for a workflow where failure makes all remaining work invalid.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all" rel="noopener noreferrer"&gt;&lt;code&gt;Promise.all()&lt;/code&gt;&lt;/a&gt; rejects when an input promise rejects. That rejection does not cancel the underlying operations. Replacing it with &lt;code&gt;Promise.allSettled()&lt;/code&gt; changes how you collect outcomes; it still does not limit when tasks begin.&lt;/p&gt;

&lt;h2&gt;
  
  
  A small pool with an explicit contract
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;pool.mjs&lt;/code&gt;. It accepts an array, a positive integer limit, and a callback. The array's values are copied before work starts; objects inside it are still shared references. Empty input returns an empty result array.&lt;/p&gt;

&lt;p&gt;The callback must return a value or a promise covering the &lt;strong&gt;whole task&lt;/strong&gt;. If it launches background work and returns early, the pool cannot track that work.&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mapSettledLimit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;items must be an array&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RangeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;limit must be a positive safe integer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;function&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;task must be a function&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;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&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;results&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;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&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;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;try&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;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fulfilled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rejected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reason&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&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;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="p"&gt;},&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;worker&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;results&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;Each worker claims an index, awaits its task, records the outcome, then claims another index. At most &lt;code&gt;limit&lt;/code&gt; workers exist. A worker cannot start another callback while it is waiting for its current one.&lt;/p&gt;

&lt;p&gt;The index claim contains no &lt;code&gt;await&lt;/code&gt;, so workers in this single JavaScript execution context cannot both claim the same index. This is not a locking strategy for shared memory across worker threads.&lt;/p&gt;

&lt;p&gt;Results go into &lt;code&gt;results[index]&lt;/code&gt;, rather than being appended when tasks finish. A slow first task therefore stays first in the returned array. Both synchronous throws and rejected promises become rejected result entries.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Promise.all()&lt;/code&gt; still appears in the implementation, but it joins a bounded set of workers. The pool creates promises for the workers, rather than eagerly creating one task promise for every input.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prove the ceiling without sending real requests
&lt;/h2&gt;

&lt;p&gt;Save this beside it as &lt;code&gt;pool-demo.mjs&lt;/code&gt;, then run &lt;code&gt;node pool-demo.mjs&lt;/code&gt; with Node.js 22 or newer. The tasks yield to another event-loop turn so that several can remain active together. One task fails deliberately.&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;assert&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;node:assert/strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;setImmediate&lt;/span&gt; &lt;span class="nx"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;yieldTurn&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;node:timers/promises&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;mapSettledLimit&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;./pool.mjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;peak&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&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;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;mapSettledLimit&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;peak&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;peak&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;yieldTurn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;deliberate failure&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;peak&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rejected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deepEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fulfilled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Peak active tasks:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;peak&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Statuses:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;, &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 output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Peak active tasks: 3
Statuses: fulfilled, fulfilled, rejected, fulfilled, fulfilled, fulfilled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important assertions are the ceiling, the return to zero active tasks, the recorded failure, and the successful results that follow it. Elapsed time alone would be a weak test: a fast script can still start too much work at once.&lt;/p&gt;

&lt;p&gt;For this article, the published example ran on Linux with Node.js &lt;strong&gt;22.22.1&lt;/strong&gt;. Eight additional local checks passed, covering eager unbounded starts, blocked admission, reverse completion order, synchronous and asynchronous failures, empty input, invalid arguments, and one-worker and oversized-limit cases. These establish the pool's local behaviour, not an API provider's capacity or a production throughput claim.&lt;/p&gt;

&lt;h2&gt;
  
  
  Put the limit around the resource you need to protect
&lt;/h2&gt;

&lt;p&gt;A callback like this keeps its slot until the response body has been parsed:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;mapSettledLimit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/records/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`HTTP &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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;That URL is an illustrative route in a browser application; replace it with your own endpoint. The explicit &lt;code&gt;await&lt;/code&gt; makes the lifetime visible: the task includes reading the JSON, not merely receiving response headers.&lt;/p&gt;

&lt;p&gt;If one callback launches ten requests internally, a three-worker pool can still produce thirty active requests. Put admission control at the boundary where the constrained operation actually starts, or make the callback perform one such operation at a time.&lt;/p&gt;

&lt;p&gt;Likewise, separate calls to this helper have separate limits. Five batches running together do not share a three-request ceiling. A service-wide limit needs a shared scheduler at the appropriate process or infrastructure boundary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concurrency, rate and memory are separate budgets
&lt;/h2&gt;

&lt;p&gt;Three active requests can complete very quickly and be replaced immediately. A concurrency ceiling therefore does not mean three requests per second. A provider's quota may require a rate limiter, bounded retries, or both. When a response is &lt;code&gt;429&lt;/code&gt;, follow the endpoint's retry contract; Jitsumi's &lt;a href="https://jitsumi.com/posts/http-429-retry-after-backoff-jitter-api-client" rel="noopener noreferrer"&gt;guide to &lt;code&gt;Retry-After&lt;/code&gt;, backoff and jitter&lt;/a&gt; explains that separate decision.&lt;/p&gt;

&lt;p&gt;The helper also retains the input snapshot and every result. Its memory usage grows with the batch size. For an endless feed or very large dataset, use a streaming design that bounds buffered input and lets a consumer process results incrementally.&lt;/p&gt;

&lt;p&gt;Finally, a hung task holds its slot indefinitely. Timeouts and cancellation belong to the operation's own contract. A timeout that only stops waiting can free a slot while the underlying request continues, defeating the resource limit you thought you had. Do not add automatic retries for writes until you know how the receiving API prevents duplicate effects.&lt;/p&gt;

&lt;p&gt;The example is intentionally small: no retry policy, global queue, priority system or cancellation API. Once those requirements matter, evaluate a maintained scheduler against them rather than silently turning this helper into infrastructure.&lt;/p&gt;

&lt;p&gt;Before choosing a larger concurrency value, instrument your real workload: active tasks, queue wait, task duration and error rate. Then change one limit and compare. The number is a capacity decision; the essential mechanism is keeping work unstarted until there is room for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;Documentation checked on 5 November 2026.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all" rel="noopener noreferrer"&gt;MDN: &lt;code&gt;Promise.all()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;MDN: &lt;code&gt;Array.prototype.map()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/docs/latest-v22.x/api/timers.html#timers-promises-api" rel="noopener noreferrer"&gt;Node.js: timers promises API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>jitsumi</category>
      <category>tech</category>
    </item>
  </channel>
</rss>
