<?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</title>
    <description>The most recent home feed on DEV Community.</description>
    <link>https://dev.to</link>
    <atom:link rel="self" type="application/rss+xml" href="https://bizarro.dev.to/feed"/>
    <language>en</language>
    <item>
      <title>Laravel Race Condition Fix: Stop Double-Accepted Jobs</title>
      <dc:creator>Aqib Javaid</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:40:05 +0000</pubDate>
      <link>https://dev.to/aqib_javaid/laravel-race-condition-fix-stop-double-accepted-jobs-3bo8</link>
      <guid>https://dev.to/aqib_javaid/laravel-race-condition-fix-stop-double-accepted-jobs-3bo8</guid>
      <description>&lt;p&gt;Two drivers tap &lt;strong&gt;Accept&lt;/strong&gt; on the same delivery within the same second. Both phones show a green "Job accepted" screen. Both drivers start driving. One of them arrives to find the job already gone, or worse, the customer has two vehicles outside. This is the classic Laravel race condition, and if you run any dispatch, booking or claim-the-job workflow, you will meet it the first week you have real traffic.&lt;/p&gt;

&lt;p&gt;I hit exactly this shape of problem while rebuilding the dispatch layer on &lt;a href="https://aqibjavaid.site/work/ion-dash-logistics-delivery-fleet-management" rel="noopener noreferrer"&gt;ION DASH, a logistics and fleet platform&lt;/a&gt; (Flutter apps for customers and drivers on a Laravel API). The rule the client wanted was simple: the first driver who successfully accepts a delivery secures it, and nobody else can. Making that rule true under concurrency took more care than the feature name suggests. This article is the version of that fix I would hand to another &lt;a href="https://aqibjavaid.site/services/laravel-php-development" rel="noopener noreferrer"&gt;Laravel developer&lt;/a&gt;: why the obvious code fails, four ways to fix it, which one I reach for first, and how to prove it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug report that starts it
&lt;/h2&gt;

&lt;p&gt;The symptom is never "race condition". It is a support message: &lt;em&gt;"Two drivers say they got the same order."&lt;/em&gt; Nothing in your logs is red, because each request succeeded.&lt;/p&gt;

&lt;p&gt;Here is the code that produces it. It reads like correct code, and in a single-user test it is correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Delivery&lt;/span&gt; &lt;span class="nv"&gt;$delivery&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$driver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$delivery&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'pending'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Already taken'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;409&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="nv"&gt;$delivery&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'status'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'assigned'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'driver_id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$driver&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$delivery&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fresh&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The bug is the gap between the &lt;code&gt;if&lt;/code&gt; and the &lt;code&gt;update&lt;/code&gt;. This is a check-then-act sequence, and the database can serve two requests inside that gap:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Time&lt;/th&gt;
&lt;th&gt;Driver A's request&lt;/th&gt;
&lt;th&gt;Driver B's request&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;t0&lt;/td&gt;
&lt;td&gt;reads delivery, status = &lt;code&gt;pending&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;t1&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;reads delivery, status = &lt;code&gt;pending&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;t2&lt;/td&gt;
&lt;td&gt;passes the check, writes &lt;code&gt;driver_id = A&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;t3&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;passes its (stale) check, writes &lt;code&gt;driver_id = B&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;B's write silently overwrites A's. Both got a 200. The window between t0 and t3 is only milliseconds wide, but a busy dispatch queue, a push notification that wakes many phones at once, and flaky mobile networks that retry requests all push traffic into that window. On a &lt;a href="https://aqibjavaid.site/services/mobile-app-development" rel="noopener noreferrer"&gt;mobile-backed product&lt;/a&gt; it happens far more often than you expect, because every driver receives the same "new job" push at the same moment.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Important&lt;/p&gt;
&lt;p&gt;
You cannot fix this in PHP with an &lt;code&gt;if&lt;/code&gt;. PHP processes (FPM workers, queue workers, Octane workers) don't share memory. Only the database, or a shared lock service, can decide who wins.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Four ways to fix it, and what each costs
&lt;/h2&gt;

&lt;p&gt;There are four patterns I consider. They are not equal, and the right one depends on how much state the decision touches.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;How it works&lt;/th&gt;
&lt;th&gt;Strength&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Conditional &lt;code&gt;UPDATE&lt;/code&gt; (compare-and-set)&lt;/td&gt;
&lt;td&gt;One statement: &lt;code&gt;UPDATE ... WHERE status = 'pending'&lt;/code&gt;, check affected rows&lt;/td&gt;
&lt;td&gt;Simplest, no explicit locks, fast&lt;/td&gt;
&lt;td&gt;Only guards one row's state&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pessimistic lock (&lt;code&gt;lockForUpdate&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Lock the row inside a transaction, then run any checks&lt;/td&gt;
&lt;td&gt;Lets you validate several things before writing&lt;/td&gt;
&lt;td&gt;Holds a row lock; needs a transaction; can deadlock if misused&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Atomic cache lock (&lt;code&gt;Cache::lock&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Redis-backed lock keyed by delivery id&lt;/td&gt;
&lt;td&gt;Works across tables and services&lt;/td&gt;
&lt;td&gt;A second system to fail; lock can expire mid-work&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Optimistic version column&lt;/td&gt;
&lt;td&gt;Write only if &lt;code&gt;version&lt;/code&gt; matches what you read&lt;/td&gt;
&lt;td&gt;No locks held&lt;/td&gt;
&lt;td&gt;Callers must retry; more code&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I'll go through them in the order I would try them.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Conditional update: my default
&lt;/h3&gt;

&lt;p&gt;The cleanest fix removes the gap entirely. Don't read, then write. Write with the condition inside the same statement and let the database tell you whether you won:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$won&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Delivery&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;query&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;whereKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$delivery&lt;/span&gt;&lt;span class="o"&gt;-&amp;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;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'status'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'pending'&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;whereNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'driver_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;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'status'&lt;/span&gt;      &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'assigned'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'driver_id'&lt;/span&gt;   &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$driver&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'assigned_at'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;now&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="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="nv"&gt;$won&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Already taken'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;409&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;&lt;code&gt;update()&lt;/code&gt; returns the number of rows changed. InnoDB takes a row lock while it evaluates and applies that single statement, so when two requests collide, one updates the row and the second sees &lt;code&gt;status = 'assigned'&lt;/code&gt; in its &lt;code&gt;WHERE&lt;/code&gt;, matches zero rows and returns &lt;code&gt;0&lt;/code&gt;. The decision and the write are one atomic step. In the ION DASH flow, this is the shape of "first driver to accept secures the job": the loser gets a clean 409 and the app shows "this job was just taken", instead of a false success.&lt;/p&gt;

&lt;p&gt;Use this whenever the winning condition is a property of one row. It is also the pattern I'd suggest for the claim step of any job board, booking slot or inventory reservation.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Pessimistic locking: when you must check more than one thing
&lt;/h3&gt;

&lt;p&gt;Dispatch is rarely just "is the row pending". In our case the backend also enforces a &lt;strong&gt;driver capacity limit&lt;/strong&gt; (a driver cannot hold more assignments than their configured maximum) and &lt;strong&gt;online/offline eligibility&lt;/strong&gt;. Those rules live on other rows, so a single-row conditional update is not enough.&lt;/p&gt;

&lt;p&gt;That is where &lt;a href="https://laravel.com/docs/12.x/queries" rel="noopener noreferrer"&gt;&lt;code&gt;lockForUpdate&lt;/code&gt;&lt;/a&gt; earns its place. Lock the rows you are about to reason about, inside a transaction, in a fixed order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$deliveryId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$driverId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Lock the driver first, then the delivery. Always in this order.&lt;/span&gt;
    &lt;span class="nv"&gt;$driver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Driver&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;whereKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$driverId&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;lockForUpdate&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;firstOrFail&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$driver&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;is_online&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="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ok'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'reason'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'offline'&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="nv"&gt;$active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Delivery&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'driver_id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$driver&lt;/span&gt;&lt;span class="o"&gt;-&amp;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;gt;&lt;/span&gt;&lt;span class="nf"&gt;whereIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'status'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'assigned'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'picked_up'&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="nb"&gt;count&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$active&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nv"&gt;$driver&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;max_active_jobs&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="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ok'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'reason'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'at_capacity'&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="nv"&gt;$delivery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Delivery&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;whereKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$deliveryId&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;lockForUpdate&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;firstOrFail&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$delivery&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'pending'&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="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ok'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'reason'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'taken'&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="nv"&gt;$delivery&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'status'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'assigned'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'driver_id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$driver&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&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;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ok'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&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="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Locking the &lt;strong&gt;driver&lt;/strong&gt; row is the detail people miss. If you lock only the delivery, the same driver can accept two different jobs at the same moment, both pass the capacity count, and now they are one over their limit. Locking the driver serialises that driver's own accepts.&lt;/p&gt;

&lt;p&gt;Two rules keep this safe:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Always lock in the same order&lt;/strong&gt; (driver, then delivery). Two transactions taking the same locks in opposite orders is how you get deadlocks. Laravel retries the closure for you if you pass a second argument: &lt;code&gt;DB::transaction($callback, 3)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the transaction short.&lt;/strong&gt; No HTTP calls, no push notifications and no file uploads inside it. Send the Firebase push after the commit, for example with &lt;code&gt;DB::afterCommit()&lt;/code&gt; or a queued job dispatched &lt;code&gt;-&amp;gt;afterCommit()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MySQL's own documentation on &lt;a href="https://dev.mysql.com/doc/refman/8.4/en/innodb-locking-reads.html" rel="noopener noreferrer"&gt;locking reads&lt;/a&gt; is worth ten minutes, particularly the parts on which rows get locked when your &lt;code&gt;WHERE&lt;/code&gt; clause doesn't hit an index. An unindexed lock query can lock far more rows than you intended.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Atomic cache locks: for work that spans systems
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://laravel.com/docs/12.x/cache" rel="noopener noreferrer"&gt;&lt;code&gt;Cache::lock()&lt;/code&gt;&lt;/a&gt; gives you a Redis-backed mutex:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$lock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"delivery-accept:{$delivery-&amp;gt;id}"&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="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="nv"&gt;$lock&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Busy, try again'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;409&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;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ... decide and write ...&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="nv"&gt;$lock&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;release&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I use this when the thing being protected is not a single database row: a call to an external carrier API, a document being generated, a report being rebuilt. For dispatch I avoid it as the primary guard, for a reason that matters: &lt;strong&gt;the lock and the data live in different systems&lt;/strong&gt;. If the lock expires after 10 seconds while a slow request is still working, a second request walks in. The database lock cannot expire out from under the transaction that holds it. Treat a cache lock as a traffic cop in front of the real guard, not the guard itself.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Optimistic versioning: for edit conflicts, not races to claim
&lt;/h3&gt;

&lt;p&gt;Add a &lt;code&gt;version&lt;/code&gt; integer, read it, and write with &lt;code&gt;WHERE version = :seen&lt;/code&gt;, incrementing on success. It's the right tool when many people might edit the same record over minutes (an admin editing a quote, say) and you would rather show a "someone else changed this" message than block anyone. For a first-come-first-served claim, the conditional update does the same job with less code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Auto-assignment makes the race worse
&lt;/h2&gt;

&lt;p&gt;Accept-by-tap is one writer. The other writer is your own scheduler. On ION DASH, an order that stays in the queue for 15 minutes is automatically assigned to an available driver. That means a driver tapping &lt;strong&gt;Accept&lt;/strong&gt; and the scheduled auto-assign command can target the same delivery at the same instant.&lt;/p&gt;

&lt;p&gt;The fix is the same principle applied to both paths: they must go through &lt;strong&gt;one&lt;/strong&gt; method that performs the guarded write, rather than each carrying its own copy of the rules. When I see two code paths that both set &lt;code&gt;driver_id&lt;/code&gt;, I treat that as a bug waiting to happen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// One door in. The controller and the scheduled command both call this.&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ClaimDelivery&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$deliveryId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$driverId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// conditional update + capacity checks live here, nowhere else&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;Also stop the scheduler overlapping itself. If the command takes longer than its interval, two copies run at once, which is another source of double assignment. Laravel's &lt;a href="https://laravel.com/docs/12.x/scheduling" rel="noopener noreferrer"&gt;&lt;code&gt;withoutOverlapping()&lt;/code&gt;&lt;/a&gt; uses an atomic lock for exactly this, and &lt;code&gt;onOneServer()&lt;/code&gt; covers multi-server deployments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test it with real concurrency
&lt;/h2&gt;

&lt;p&gt;A feature test that calls the endpoint twice in a row will pass against the broken code, because the second call runs after the first has finished. To expose a race you need two database connections acting at the same time.&lt;/p&gt;

&lt;p&gt;My checklist when I review claim logic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[x] The check and the write are one statement, or one transaction holding a lock&lt;/li&gt;
&lt;li&gt;[x] Losing the race returns a clear 409 the mobile app can show&lt;/li&gt;
&lt;li&gt;[x] Every path that assigns a driver goes through the same method&lt;/li&gt;
&lt;li&gt;[x] Locks are always taken in the same order&lt;/li&gt;
&lt;li&gt;[x] No network calls inside a transaction&lt;/li&gt;
&lt;li&gt;[x] A concurrency test fires 20 or more simultaneous accepts at one delivery and asserts exactly one winner&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For that last item, a small script is enough. Run it against a real MySQL database, not SQLite, because SQLite serialises all writes and hides the problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"20 parallel accepts"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
seq 1 20 &lt;span class="o"&gt;|&lt;/span&gt; xargs -P 20 -I&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt; curl -s -o /dev/null -w &lt;span class="s2"&gt;"%{http_code}\n"&lt;/span&gt; \
  -X POST https://staging.example.test/api/deliveries/42/accept \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $(cat tokens/driver-{}.txt)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You expect exactly one &lt;code&gt;200&lt;/code&gt; and nineteen &lt;code&gt;409&lt;/code&gt; responses. Against the check-then-update version, you can see more than one &lt;code&gt;200&lt;/code&gt;, and an &lt;code&gt;assigned&lt;/code&gt; row whose &lt;code&gt;driver_id&lt;/code&gt; is whichever request wrote last.&lt;/p&gt;

&lt;h2&gt;
  
  
  When not to over-engineer this
&lt;/h2&gt;

&lt;p&gt;Not every status change needs a lock. I skip all of this when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;There is only ever one writer.&lt;/strong&gt; A background job that owns a record doesn't need to protect it from itself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The operation is naturally idempotent.&lt;/strong&gt; Marking an already-delivered order as delivered again is harmless. (Retries of &lt;em&gt;payments&lt;/em&gt; are different, and need &lt;a href="https://aqibjavaid.site/blog/laravel-api-idempotency-keys" rel="noopener noreferrer"&gt;idempotency keys&lt;/a&gt;.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Traffic is tiny.&lt;/strong&gt; An internal tool with three users can live with a &lt;code&gt;409&lt;/code&gt; from a unique constraint.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A database &lt;strong&gt;unique index&lt;/strong&gt; is also worth knowing as a backstop. If a business rule says "one active assignment per delivery", enforce it with a unique key on a nullable &lt;code&gt;active_driver_slot&lt;/code&gt; or a similar column, so that even a bug in your application code cannot create a double assignment. The code is your first defence and the schema is your last.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd do again, and what I'd change
&lt;/h2&gt;

&lt;p&gt;What worked on ION DASH: one claim method, conditional update first, row locks only where the capacity rules needed them, and pushes sent after commit. Losing drivers get an immediate, explicit "already taken" response instead of a ghost job.&lt;/p&gt;

&lt;p&gt;What I'd watch for next time: lock-wait timeouts under heavy load. If many drivers fight for the same hot row, MySQL's &lt;code&gt;SKIP LOCKED&lt;/code&gt; (available in 8.0+) lets workers skip rows that are already locked, which suits a queue where any available job will do. It doesn't suit a case where drivers want one specific job, but it is the right tool for pulling "the next available" item. Queue workers raise the same class of problem, and I covered the design side in the &lt;a href="https://aqibjavaid.site/blog/laravel-queue-architecture-saas" rel="noopener noreferrer"&gt;Laravel queue architecture guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is &lt;code&gt;lockForUpdate&lt;/code&gt; enough to prevent double booking in Laravel?
&lt;/h3&gt;

&lt;p&gt;Only inside a database transaction. Outside one, the lock is released the moment the statement ends. Wrap the read and the write together in &lt;code&gt;DB::transaction()&lt;/code&gt;, and lock every row whose state your decision depends on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I use Redis locks or database locks for first-come-first-served claims?
&lt;/h3&gt;

&lt;p&gt;Prefer the database when the thing being claimed is a row. The lock lives with the data and can't expire mid-decision. Use Redis locks to protect work that spans several systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does my concurrency test pass on my machine but fail in production?
&lt;/h3&gt;

&lt;p&gt;Local tests often run on SQLite or run requests one at a time. Test against MySQL or PostgreSQL with real parallel connections.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does this apply to mobile app backends specifically?
&lt;/h3&gt;

&lt;p&gt;It applies to any API, but mobile backends hit it sooner. A single push notification can wake hundreds of devices at once, and flaky networks make clients retry requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Read-then-write is a race. Move the condition into the &lt;code&gt;UPDATE&lt;/code&gt;'s &lt;code&gt;WHERE&lt;/code&gt; clause and check the affected-row count.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;lockForUpdate&lt;/code&gt; inside a short transaction when the decision involves more than one row, and lock in a consistent order.&lt;/li&gt;
&lt;li&gt;Put one claim method behind every code path, including scheduled auto-assignment.&lt;/li&gt;
&lt;li&gt;Redis locks are a traffic cop, not the source of truth. A unique index is your last line of defence.&lt;/li&gt;
&lt;li&gt;Prove it with 20 parallel requests against MySQL, expecting exactly one winner.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are building dispatch, booking or marketplace logic and want it reviewed by someone who has shipped it, &lt;a href="https://aqibjavaid.site/book" rel="noopener noreferrer"&gt;book a call&lt;/a&gt; and we can look at your claim flow together.&lt;/p&gt;

&lt;p&gt;Originally published at &lt;a href="https://aqibjavaid.site/blog/laravel-race-condition-double-accept-fix" rel="noopener noreferrer"&gt;aqibjavaid.site&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>mysql</category>
      <category>backend</category>
    </item>
    <item>
      <title>What Android 14, 15 and 16 still let a background video recorder do</title>
      <dc:creator>TheChemical</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:40:04 +0000</pubDate>
      <link>https://dev.to/thechemical/what-android-14-15-and-16-still-let-a-background-video-recorder-do-46k7</link>
      <guid>https://dev.to/thechemical/what-android-14-15-and-16-still-let-a-background-video-recorder-do-46k7</guid>
      <description>&lt;p&gt;I work on &lt;a href="https://play.google.com/store/apps/details?id=me.jagar.xscamera2" rel="noopener noreferrer"&gt;XSCamera&lt;/a&gt;, a background video recorder for Android. It records with the screen off or while you use another app. It has a bit over 6 million installs, which mostly means we get to find every edge case in production.&lt;/p&gt;

&lt;p&gt;People regularly ask whether this kind of app is "still possible" on new Android versions. It is. But the list of things you must do correctly gets longer every year, and the failure mode is nasty: the app installs, the button works, and the recording silently never starts or dies ten minutes in.&lt;/p&gt;

&lt;p&gt;This is the short version of what we've learned. If you're building anything that holds the camera or microphone while the user is elsewhere (a dashcam, a baby monitor, a bodycam for cyclists), most of it applies to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rules, by version
&lt;/h2&gt;

&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%2F6ezdo5l30qeci1ra4q04.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%2F6ezdo5l30qeci1ra4q04.png" alt="Android versions and what each one changed for background camera use" width="799" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android 9&lt;/strong&gt; cut off camera and microphone access for apps that are idle in the background. From here on you need a foreground service, and a foreground service means a notification. That's the end of "invisible" recorders, seven years ago now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android 10 and 11&lt;/strong&gt; introduced &lt;code&gt;foregroundServiceType&lt;/code&gt; and then enforced it for camera and microphone. A service that touches the camera without &lt;code&gt;camera&lt;/code&gt; in its type gets nothing but black frames or an exception, depending on the device.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android 12&lt;/strong&gt; did two things. It added the green privacy indicator, which the system draws and you cannot influence. And it blocked starting a foreground service from the background in most cases (&lt;code&gt;ForegroundServiceStartNotAllowedException&lt;/code&gt;). In practice: start the service while your activity is visible, in response to a tap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android 13&lt;/strong&gt; made the notification permission a runtime permission, and gave users a "stop" button for foreground services in the notification drawer. If your service is stopped from there, you get no polite callback. Plan for it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android 14&lt;/strong&gt; is the one that broke old apps. Every foreground service must declare a type, each type needs its own permission (&lt;code&gt;FOREGROUND_SERVICE_CAMERA&lt;/code&gt;, &lt;code&gt;FOREGROUND_SERVICE_MICROPHONE&lt;/code&gt;), and the system checks at start time that you actually hold the runtime permission for that type. Miss any of it and &lt;code&gt;startForeground()&lt;/code&gt; throws a &lt;code&gt;SecurityException&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android 15&lt;/strong&gt; tightened what may be started from &lt;code&gt;BOOT_COMPLETED&lt;/code&gt;. A camera service started at boot is not allowed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The minimum that works
&lt;/h2&gt;

&lt;p&gt;Manifest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.CAMERA"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.RECORD_AUDIO"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.FOREGROUND_SERVICE"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.FOREGROUND_SERVICE_CAMERA"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.FOREGROUND_SERVICE_MICROPHONE"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.POST_NOTIFICATIONS"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;service&lt;/span&gt;
    &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;".RecordingService"&lt;/span&gt;
    &lt;span class="na"&gt;android:exported&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;
    &lt;span class="na"&gt;android:foregroundServiceType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"camera|microphone"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Starting it, from an activity that is on screen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// In the activity, after CAMERA and RECORD_AUDIO are granted&lt;/span&gt;
&lt;span class="nc"&gt;ContextCompat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startForegroundService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;RecordingService&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// In the service&lt;/span&gt;
&lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onStartCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Intent&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;startId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ServiceInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;FOREGROUND_SERVICE_TYPE_CAMERA&lt;/span&gt; &lt;span class="ow"&gt;or&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="n"&gt;recordAudio&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;ServiceInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;FOREGROUND_SERVICE_TYPE_MICROPHONE&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;ServiceCompat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startForeground&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;NOTIFICATION_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;buildNotification&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="n"&gt;types&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;openCameraAndRecord&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="no"&gt;START_NOT_STICKY&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details in there are not decoration.&lt;/p&gt;

&lt;p&gt;Only pass the microphone type if you hold &lt;code&gt;RECORD_AUDIO&lt;/code&gt;. If the user turned sound off and denied the permission, including that type throws on Android 14.&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;START_NOT_STICKY&lt;/code&gt; is deliberate. If the system kills you and restarts the service later, you're now a service started from the background, which can't get the camera. Better to stop cleanly and tell the user than to come back as a zombie holding a notification and recording nothing.&lt;/p&gt;

&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%2Fuxh0vt0f1rv47pfsb7lk.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%2Fuxh0vt0f1rv47pfsb7lk.png" alt="The order of events that keeps camera access after the screen turns off" width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The bugs that actually cost us
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The timestamp overlay.&lt;/strong&gt; Our users like a date and time burned into the video. In one release line we drew that overlay on the main thread, once per frame. On fast phones nobody noticed. On slow ones, with a 4K preview, the main thread fell behind, and our ANR rate climbed from 0.28% to 0.40%. Google's bad-behaviour threshold is 0.47%, and Play shows your app less once you cross it, so that was close enough to ruin a week. The fix was boring: the overlay got its own thread. The lesson was less boring. A camera app has a hot loop, and anything on the main thread inside it is a liability on a 2 GB phone, even if it profiles fine on your desk.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Battery managers.&lt;/strong&gt; A correct foreground service is still not safe on many phones. Samsung, Xiaomi, Oppo and Vivo all ship their own task killers on top of Android's. The only real fix is on the user's side (battery set to Unrestricted, autostart on Xiaomi), so the app has to detect the situation and explain it, with the exact path for that manufacturer. &lt;a href="https://dontkillmyapp.com" rel="noopener noreferrer"&gt;dontkillmyapp.com&lt;/a&gt; keeps the list. We read 2,187 low-star reviews across the big apps in this category and "it stopped by itself" was the number one complaint, 340 of them. Most of those are this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The file that won't play.&lt;/strong&gt; A normal MP4 gets its index written when recording stops. If the process dies first (battery killer, crash, full disk), you have a large file that no player will open. It was the smallest group in those reviews, 115, and the angriest. If you record long sessions, don't rely on a clean stop: write in segments or use a container layout that stays readable. Then test it by killing your own process mid-recording.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Storage.&lt;/strong&gt; 4K runs about 350 MB a minute. Users don't do that maths, so do it for them and show the remaining minutes before they press record.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd check before shipping
&lt;/h2&gt;

&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%2Fjm7iex8ztstj3cpsva1u.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%2Fjm7iex8ztstj3cpsva1u.png" alt="Checklist for a background camera service" width="799" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Service declares &lt;code&gt;camera&lt;/code&gt; (and &lt;code&gt;microphone&lt;/code&gt; if used), with both &lt;code&gt;FOREGROUND_SERVICE_*&lt;/code&gt; permissions in the manifest.&lt;/li&gt;
&lt;li&gt;Service is started from a visible activity, after the runtime permissions are granted.&lt;/li&gt;
&lt;li&gt;The types passed to &lt;code&gt;startForeground()&lt;/code&gt; match the permissions you hold right now.&lt;/li&gt;
&lt;li&gt;The notification is real and useful: what's recording, for how long, a Stop action. Reviewers at Play look at this, and so do users.&lt;/li&gt;
&lt;li&gt;Nothing per-frame runs on the main thread.&lt;/li&gt;
&lt;li&gt;Kill the process mid-recording. Is the file playable?&lt;/li&gt;
&lt;li&gt;Run it for an hour with the screen off on a Samsung and a Xiaomi with default battery settings. Then with Unrestricted. Know the difference and tell your users.&lt;/li&gt;
&lt;li&gt;Fill the storage during a recording. Do you stop cleanly?&lt;/li&gt;
&lt;li&gt;Fill in Play Console's foreground service declaration and record the demo video before you upload, not after the rejection.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One more thing
&lt;/h2&gt;

&lt;p&gt;Don't promise hidden recording in your listing. It isn't possible, so it's a false claim, and Play removes apps for it under the stalkerware policy. The honest pitch (keeps recording when the screen is off, always shows that it is recording) is also the one that survives review.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I'm on the team behind XSCamera at XS Labs. The review counts come from our own read of public Play reviews in November 2026. If something here is wrong for a device you know well, I'd like to hear it.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>camera</category>
      <category>mobile</category>
    </item>
    <item>
      <title>How to track hotel prices with Python: 6 Barcelona hotels on 14 dates</title>
      <dc:creator>Monkey.D.Scraping</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:39:27 +0000</pubDate>
      <link>https://dev.to/monkeydscraping/how-to-track-hotel-prices-with-python-6-barcelona-hotels-on-14-dates-1kje</link>
      <guid>https://dev.to/monkeydscraping/how-to-track-hotel-prices-with-python-6-barcelona-hotels-on-14-dates-1kje</guid>
      <description>&lt;p&gt;"What's the best day to book a hotel?" has a thousand blog answers and almost no data behind them. I wanted my own numbers, so I built a small hotel price tracker and pointed it at Barcelona.&lt;/p&gt;

&lt;p&gt;Disclosure: it runs on a Google Hotels scraper I built and sell on Apify, and an AI assistant helped me draft this post. Every number below comes from runs I did on November 17, 2026.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;6 Barcelona hotels, from hostel to 5-star: Generator Barcelona, Casa Gràcia, Occidental Atenea Mar, Novotel Barcelona City, Hotel Catalonia Ramblas, NH Collection Gran Hotel Calderón&lt;/li&gt;
&lt;li&gt;14 arrival dates between December 7, 2026 and February 5, 2027, every Monday and Friday, 2 nights each&lt;/li&gt;
&lt;li&gt;2 adults, USD, cheapest offer across all booking sites&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why fixed hotels? Because the "top 20 hotels in Barcelona" list changes with the dates. Across my runs only 2 to 9 of the 20 hotels stayed the same, so averaging a city search would compare different hotels. Tracking specific hotels by their Google Hotels link fixes that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hotel prices over time: the results
&lt;/h2&gt;

&lt;p&gt;Cheapest price per night, in USD:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Arrival&lt;/th&gt;
&lt;th&gt;Day&lt;/th&gt;
&lt;th&gt;Novotel City&lt;/th&gt;
&lt;th&gt;Catalonia Ramblas&lt;/th&gt;
&lt;th&gt;Occidental Atenea Mar&lt;/th&gt;
&lt;th&gt;NH Gran Hotel Calderón&lt;/th&gt;
&lt;th&gt;Generator&lt;/th&gt;
&lt;th&gt;Casa Gràcia&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Dec 7&lt;/td&gt;
&lt;td&gt;Mon&lt;/td&gt;
&lt;td&gt;184&lt;/td&gt;
&lt;td&gt;254&lt;/td&gt;
&lt;td&gt;114&lt;/td&gt;
&lt;td&gt;240&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dec 11&lt;/td&gt;
&lt;td&gt;Fri&lt;/td&gt;
&lt;td&gt;144&lt;/td&gt;
&lt;td&gt;252&lt;/td&gt;
&lt;td&gt;122&lt;/td&gt;
&lt;td&gt;232&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dec 14&lt;/td&gt;
&lt;td&gt;Mon&lt;/td&gt;
&lt;td&gt;144&lt;/td&gt;
&lt;td&gt;336&lt;/td&gt;
&lt;td&gt;114&lt;/td&gt;
&lt;td&gt;265&lt;/td&gt;
&lt;td&gt;147&lt;/td&gt;
&lt;td&gt;55&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dec 18&lt;/td&gt;
&lt;td&gt;Fri&lt;/td&gt;
&lt;td&gt;158&lt;/td&gt;
&lt;td&gt;168&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;252&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dec 21&lt;/td&gt;
&lt;td&gt;Mon&lt;/td&gt;
&lt;td&gt;137&lt;/td&gt;
&lt;td&gt;186&lt;/td&gt;
&lt;td&gt;118&lt;/td&gt;
&lt;td&gt;272&lt;/td&gt;
&lt;td&gt;118&lt;/td&gt;
&lt;td&gt;108&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dec 28&lt;/td&gt;
&lt;td&gt;Mon&lt;/td&gt;
&lt;td&gt;224&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;173&lt;/td&gt;
&lt;td&gt;344&lt;/td&gt;
&lt;td&gt;181&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 4&lt;/td&gt;
&lt;td&gt;Mon&lt;/td&gt;
&lt;td&gt;132&lt;/td&gt;
&lt;td&gt;186&lt;/td&gt;
&lt;td&gt;106&lt;/td&gt;
&lt;td&gt;318&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 8&lt;/td&gt;
&lt;td&gt;Fri&lt;/td&gt;
&lt;td&gt;132&lt;/td&gt;
&lt;td&gt;168&lt;/td&gt;
&lt;td&gt;114&lt;/td&gt;
&lt;td&gt;282&lt;/td&gt;
&lt;td&gt;133&lt;/td&gt;
&lt;td&gt;108&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 11&lt;/td&gt;
&lt;td&gt;Mon&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;168&lt;/td&gt;
&lt;td&gt;106&lt;/td&gt;
&lt;td&gt;356&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 15&lt;/td&gt;
&lt;td&gt;Fri&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;218&lt;/td&gt;
&lt;td&gt;126&lt;/td&gt;
&lt;td&gt;247&lt;/td&gt;
&lt;td&gt;130&lt;/td&gt;
&lt;td&gt;112&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 18&lt;/td&gt;
&lt;td&gt;Mon&lt;/td&gt;
&lt;td&gt;299&lt;/td&gt;
&lt;td&gt;915&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;1,285&lt;/td&gt;
&lt;td&gt;138&lt;/td&gt;
&lt;td&gt;140&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 22&lt;/td&gt;
&lt;td&gt;Fri&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;168&lt;/td&gt;
&lt;td&gt;130&lt;/td&gt;
&lt;td&gt;216&lt;/td&gt;
&lt;td&gt;130&lt;/td&gt;
&lt;td&gt;138&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Feb 1&lt;/td&gt;
&lt;td&gt;Mon&lt;/td&gt;
&lt;td&gt;308&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;274&lt;/td&gt;
&lt;td&gt;527&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;217&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Feb 5&lt;/td&gt;
&lt;td&gt;Fri&lt;/td&gt;
&lt;td&gt;162&lt;/td&gt;
&lt;td&gt;230&lt;/td&gt;
&lt;td&gt;176&lt;/td&gt;
&lt;td&gt;312&lt;/td&gt;
&lt;td&gt;158&lt;/td&gt;
&lt;td&gt;184&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A dash means no offer was listed for that date.&lt;/p&gt;

&lt;h2&gt;
  
  
  When are hotel prices cheapest?
&lt;/h2&gt;

&lt;p&gt;Three things jumped out:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The week matters far more than the weekday.&lt;/strong&gt; The same hotel swung up to 6× between weeks: NH Gran Hotel Calderón went from $216 to $1,285 a night, Catalonia Ramblas from $168 to $915. Both spikes landed on the same Monday, January 18. That's what a city event looks like in hotel data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monday vs Friday was a coin flip.&lt;/strong&gt; Median Monday price was lower than Friday for 2 hotels and higher for 4. No universal "cheapest day of the week" here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Holidays cost extra, but less than events.&lt;/strong&gt; December 28 was pricier than early December for every hotel with a price that day, but nowhere near the January 18 spike.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So the honest answer to "best day to book a hotel" from this data: avoid the event weeks, then any weekday is fine. And that's about &lt;em&gt;stay&lt;/em&gt; dates. When you &lt;em&gt;buy&lt;/em&gt; is a different question, and it's exactly what a tracker answers: same stay, checked again every day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build your own hotel price tracker in Python
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;apify_client&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ApifyClient&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ApifyClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"APIFY_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="no"&gt;HOTELS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;  &lt;span class="c1"&gt;# Google Hotels links or "hotel name + city"&lt;/span&gt;
    &lt;span class="s2"&gt;"Generator Barcelona"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Occidental Atenea Mar Barcelona"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cheapest_per_night&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;check_in&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nights&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&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="o"&gt;-&amp;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;run&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;actor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"monkey.d.scraping/google-hotels-room-offers"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;run_input&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"hotels"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;HOTELS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"checkIn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;check_in&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&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="s2"&gt;"checkOut"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;check_in&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;nights&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="nf"&gt;isoformat&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="s2"&gt;"currency"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"USD"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"maxOffersPerHotel"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&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="n"&gt;best&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;offer&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;default_dataset_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;iterate_items&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="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;offer&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"stayTotalDisplayed"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;nights&lt;/span&gt;
        &lt;span class="n"&gt;best&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;offer&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"hotelName"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&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;best&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="n"&gt;offer&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"hotelName"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&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;best&lt;/span&gt;

&lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2027&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;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;week&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;day&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weeks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;week&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;cheapest_per_night&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;day&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;Two ways to use it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Find the cheapest dates:&lt;/strong&gt; loop over arrival dates like above, then pick the lowest row.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Get a hotel price drop alert:&lt;/strong&gt; run the same stay every morning on an Apify schedule. The Actor can also compare a run with the previous one and export the price changes to CSV, so you only look at what moved.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole Barcelona experiment (14 runs, 2,760 rows of offers) cost about $0.18.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is the best day to book a hotel?&lt;/strong&gt; For stay dates, the week matters much more than the weekday: avoid event weeks. For the purchase date, track the same stay over time and buy after a drop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do I track hotel price history?&lt;/strong&gt; Save the cheapest price for the same hotel and stay every day. A scheduled script like the one above builds the history for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I track Google Hotels prices automatically?&lt;/strong&gt; Yes. Google Hotels lists the price of every booking site for a hotel; my &lt;a href="https://apify.com/monkey.d.scraping/google-hotels-room-offers" rel="noopener noreferrer"&gt;Google Hotels API on Apify&lt;/a&gt; returns those prices as JSON, by hotel or by city.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is it free?&lt;/strong&gt; You pay $0.05 per 1,000 results plus $0.003 per run, and the Apify free plan covers a lot of tracking.&lt;/p&gt;

&lt;p&gt;Next I want to run the same thing on a beach city in summer. Suggestions welcome in the comments.&lt;/p&gt;

</description>
      <category>python</category>
      <category>travel</category>
      <category>datascience</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The IT Side of a Pen Test Week, a Client-Side Runbook</title>
      <dc:creator>Uprite Services</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:38:53 +0000</pubDate>
      <link>https://dev.to/upriteservices/the-it-side-of-a-pen-test-week-a-client-side-runbook-52i</link>
      <guid>https://dev.to/upriteservices/the-it-side-of-a-pen-test-week-a-client-side-runbook-52i</guid>
      <description>&lt;p&gt;A pen tester at a company of 30 to 80 people usually works for 3 to 5 days, and the prep around those days takes closer to 4 weeks. This is the runbook I use from the client side for the IT part of that month, written for whoever on staff ends up owning it.&lt;br&gt;
Defending against the tester isn't on the list. What is on it is knowing which traffic is theirs, not changing the network mid-test, having someone who can stop things, and protecting the old servers that can't take much load.&lt;br&gt;
The problem&lt;br&gt;
The report you pay for describes one week of your network. Push a firewall change on day 2, or let the tester get blocked on day 1, and it ends up describing a week that didn't really happen, which nobody on your side can do much with.&lt;br&gt;
NIST SP 800-115 calls planning the first phase of a security test (it comes before any testing traffic is sent), and in my experience nearly all of the planning below lands on IT.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get the tester's source addresses into the scope letter
Along with the systems in scope by IP address, domain and application, the dates and hours, and banned actions such as denial of service or copying real customer records, the scope letter we use lists the addresses the tester will work from.
That last item is for the logs. After the test I go through the client's firewall logs with that address list next to them, and anything from those addresses is the tester's, while anything else that hit the edge that week gets looked at on its own. Without the list we'd be going back and forth on every odd connection.&lt;/li&gt;
&lt;li&gt;Decide what your monitoring provider is told
I don't think there's a clean answer here, and the options I weigh with clients look like this.
Tell nobody at the provider, and you find out whether they'd have caught a real intruder.
Tell their whole analyst team, and the test stops telling you anything about detection.
Tell nobody and get blocked the morning of day 1, and on a 5-day test that's 20% of what you paid for gone.
My compromise is one senior person at the provider who knows, and nobody on their analyst floor. If you use (or are about to sign with) a managed detection and response provider, ask before signing how they'd treat alerts from the tester's addresses.
As for your own staff, the CIS Controls v8.1 guidance on penetration testing says only a few people in an organization should know, with one person named as the main contact if something goes wrong. On my projects that's the owner, the IT lead, and whichever manager has a team that might notice odd logins (plus HR, in writing, before the first phishing email is sent if phishing is in scope).&lt;/li&gt;
&lt;li&gt;Patch the edge before the tester arrives
CISA added 321 entries to its Known Exploited Vulnerabilities catalog between November 17, 2025 and November 13, 2026. Of those, 64 were in firewall and remote access products from makers like Cisco, Fortinet, Ivanti, SonicWall and Citrix, and Microsoft products accounted for another 42. Since that's the gear attackers go after first, it's also the gear my clients patch first.
On our countdown that happens 10 days before kickoff. Check those entries against your own firewall, VPN and Microsoft products, update firmware, turn on MFA for every admin and remote access account, change default passwords, and leave the rest alone. I know some prep guides say to fix everything first. I don't agree, since then you're paying a tester to confirm your scan results.
The snag I see on this step is a firmware update needing a maintenance window nobody booked, so I ask for that window to be booked when the letter is signed.&lt;/li&gt;
&lt;li&gt;Protect the fragile machines
Windows Server 2012 R2 is the usual one. Extended support ended in October 2023 and the last paid security update year ended October 14, 2026, and I still find those machines in Dallas server closets running payroll or a line-of-business database. They go into the scope letter with a note to test gently or skip them, along with anything else that can't take much load.
The day before testing, take a fresh backup of them. A week out (day 7 on our countdown), do one real restore of a file share or virtual machine and write down how long it took. CISA's #StopRansomware Guide says to test backup procedures regularly anyway, and a console that says "success" hasn't shown you the data comes back.&lt;/li&gt;
&lt;li&gt;Staff the window
I want 2 names and 2 cell numbers on the client side for the test window. One of them can call a pause, and the other can restart a server in the evening if one goes down. You don't need a security analyst for this. BLS counts 7,080 information security analysts in the Dallas-Fort Worth metro in May 2025 at a mean of $133,790 a year, and a 60-person company can't usually carry that salary, so the 2 names on my contact sheet tend to be someone from the IT provider and the office manager or controller.
There's a stop word as well, and testing stops when anyone says it. The letter also says what happens if the tester sees signs of a real attacker. In ours, testing pauses and the tester calls the named contact before doing anything else.&lt;/li&gt;
&lt;li&gt;Freeze changes
Hold off on nonurgent changes for the week. A firewall rule somebody pushes on Wednesday can leave Thursday's results unreadable, since then you can't say which configuration the tester saw.&lt;/li&gt;
&lt;li&gt;Handle the report like a credential
CIS warns the report can work as step-by-step directions for breaking in. I keep copies to the 2 or 3 people doing the fixes, and one goes in the client's security records. When testing ends on a Friday, the readout call goes on the calendar for the next week, 2 or 3 days of IT time get blocked right after it for the critical findings, and a retest is set about 30 days out.
Gotchas
On the countdown I send Dallas clients about a month out, these are the snags that come up at the IT steps.
Staffing (step 9 on the full countdown) goes wrong when the only admin has vacation booked that week.
On step 6 it's a firmware update that needs a maintenance window nobody booked.
At step 8 the SOC blocks the tester on day 1, and the test stalls.
For step 7, a backup job that reports success turns out never to have been restored.
And at step 10 the report lands, then sits in an inbox for a quarter.
Takeaway
Looking back over that list, very little of it is security work in the usual sense. It's logistics, and when it's done the report you get back should describe the network you actually run rather than a week of blocked traffic and half-made changes.
The full 10-step version, including the Texas law behind the scope letter and vendor approvals, is in our guide on how to prepare for a penetration test in Dallas.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>cybersecurity</category>
      <category>infosec</category>
      <category>security</category>
    </item>
    <item>
      <title>Crypto price alerts with n8n and CoinGecko, no API key (free workflow)</title>
      <dc:creator>Relaybrook</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:38:42 +0000</pubDate>
      <link>https://dev.to/relaybrook/crypto-price-alerts-with-n8n-and-coingecko-no-api-key-free-workflow-1hp8</link>
      <guid>https://dev.to/relaybrook/crypto-price-alerts-with-n8n-and-coingecko-no-api-key-free-workflow-1hp8</guid>
      <description>&lt;p&gt;I wanted a simple thing: a message in Discord (or Telegram) when bitcoin drops below a line I care about, without signing up for an exchange, without an API key, and without an alert app pinging me every five minutes while the price sits there.&lt;/p&gt;

&lt;p&gt;n8n can do this with about a dozen core nodes. Below is how it works step by step, and the finished workflow is free on GitHub if you'd rather import it than build it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free workflow (JSON + README):&lt;/strong&gt; &lt;a href="https://github.com/Relaybrook/n8n-free-workflows/tree/main/workflows/crypto-price-alert-lite" rel="noopener noreferrer"&gt;https://github.com/Relaybrook/n8n-free-workflows/tree/main/workflows/crypto-price-alert-lite&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;n8n (self-hosted via Docker or &lt;code&gt;npx n8n&lt;/code&gt;, or n8n Cloud). I tested on self-hosted n8n 2.47.7.&lt;/li&gt;
&lt;li&gt;Somewhere to receive alerts: a Discord or Slack incoming-webhook URL, any URL that accepts a JSON POST, or a Telegram bot.&lt;/li&gt;
&lt;li&gt;No CoinGecko key. The public API works without one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Get prices from CoinGecko in one request
&lt;/h2&gt;

&lt;p&gt;CoinGecko's &lt;code&gt;/simple/price&lt;/code&gt; endpoint returns the price of several coins in one call:&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="na"&gt;GET https://api.coingecko.com/api/v3/simple/price?ids&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;bitcoin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;ethereum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;solana&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;vs_currencies&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;usd&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;"bitcoin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"usd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;64305&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"ethereum"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"usd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;1808.75&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"solana"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"usd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;72.31&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;The &lt;code&gt;ids&lt;/code&gt; are CoinGecko coin ids, not tickers. You'll find the id in the coin's URL on coingecko.com (TON is &lt;code&gt;the-open-network&lt;/code&gt;, for example).&lt;/p&gt;

&lt;p&gt;One request per run for all coins matters, because keyless access is rate-limited per IP. Every 15 minutes is comfortable from your own server.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Keep the rules in plain text
&lt;/h2&gt;

&lt;p&gt;Instead of one IF node per coin, put the rules in a &lt;strong&gt;Set&lt;/strong&gt; node (I call it &lt;code&gt;Config&lt;/code&gt;) as one text field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bitcoin: above 70000, below 60000
ethereum: below 2000
solana: above 200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;strong&gt;Code&lt;/strong&gt; node (I named it &lt;code&gt;Parse Watchlist&lt;/code&gt;) turns that into rules and builds the URL:&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="n"&gt;cfg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="s1"&gt;'Config'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;first&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="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;rules&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="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="n"&gt;raw&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;cfg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;watchlist&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;\&lt;span class="n"&gt;n&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&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="nf"&gt;match&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="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;z0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&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="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;*:&lt;/span&gt;\&lt;span class="n"&gt;s&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="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;i&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="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&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="n"&gt;part&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;m&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="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&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="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;part&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&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="nf"&gt;match&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="n"&gt;above&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;below&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;\&lt;span class="n"&gt;s&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="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&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="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;i&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="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;coin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;m&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="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&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="n"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;r&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="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&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="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&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="nf"&gt;replace&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="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&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="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="n"&gt;coins&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="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rules&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="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;coin&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'https://api.coingecko.com/api/v3/simple/price?ids='&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;coins&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="s1"&gt;','&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;'&amp;amp;vs_currencies=usd'&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(The free workflow also reports lines it can't read instead of silently skipping them.)&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Call the API without crashing on rate limits
&lt;/h2&gt;

&lt;p&gt;Add an &lt;strong&gt;HTTP Request&lt;/strong&gt; node with URL &lt;code&gt;{{ $json.url }}&lt;/code&gt;. Under Options → Response, turn on &lt;strong&gt;Include Response Headers and Status&lt;/strong&gt; and &lt;strong&gt;Never Error&lt;/strong&gt;, and set the format to &lt;strong&gt;Text&lt;/strong&gt;. Now a &lt;code&gt;429 Too Many Requests&lt;/code&gt; comes through as data (&lt;code&gt;statusCode: 429&lt;/code&gt;) that you can handle, instead of a failed execution at 3 a.m.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Alert once, then re-arm
&lt;/h2&gt;

&lt;p&gt;This is the part most quick tutorials skip. If bitcoin is above 70,000 and your workflow runs every 15 minutes, a naive check sends the same alert 96 times a day.&lt;/p&gt;

&lt;p&gt;n8n's workflow static data fixes that. It's a small object n8n saves between production runs of an active workflow:&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="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$getWorkflowStaticData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'global'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fired&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fired&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;prices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;first&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="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&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="n"&gt;alerts&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="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="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="s1"&gt;'Parse Watchlist'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;first&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="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rules&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="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;coin&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="n"&gt;usd&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="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`${r.coin}|${r.dir}|${r.level}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dir&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'above'&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;level&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="n"&gt;hit&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fired&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;alerts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${r.coin} is ${r.dir} ${r.level} (now ${price})`&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="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fired&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fired&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&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;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;alert_count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;alerts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;alerts&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="s1"&gt;'\n'&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="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A rule fires when the price crosses the line, stays quiet while it remains there, and re-arms once the price goes back. One caveat: static data is only saved for active (scheduled) runs, not for manual test runs in the editor.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Send one message
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;IF&lt;/strong&gt; node checks &lt;code&gt;alert_count &amp;gt; 0&lt;/code&gt;. Then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Discord:&lt;/strong&gt; HTTP Request, POST to your webhook URL with body &lt;code&gt;{ "content": "&amp;lt;message&amp;gt;" }&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Slack:&lt;/strong&gt; same, with &lt;code&gt;{ "text": "&amp;lt;message&amp;gt;" }&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Telegram:&lt;/strong&gt; the Telegram node, with a bot from &lt;a class="mentioned-user" href="https://dev.to/botfather"&gt;@botfather&lt;/a&gt; and your chat id.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All alerts from one run go out as one message, never one per coin.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Test without touching the network
&lt;/h2&gt;

&lt;p&gt;I like workflows that show you the result before you configure anything. The free version has a &lt;code&gt;test_mode&lt;/code&gt; switch that is on by default: an IF node routes to a Code node returning a sample price response (made-up prices), and the message only appears in a &lt;strong&gt;Preview&lt;/strong&gt; node. Import it, click &lt;strong&gt;Execute workflow&lt;/strong&gt;, and you'll see two sample alerts in a few seconds. Set &lt;code&gt;test_mode = false&lt;/code&gt; when you're ready.&lt;/p&gt;

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

&lt;p&gt;On self-hosted n8n 2.47.7: the shipped file in test mode, the live path against a local server returning CoinGecko's response shape (Discord and Slack bodies posted to a local webhook), an unknown coin id, an unreadable line, and an HTTP 429. Telegram sending and the re-arm memory across real scheduled runs weren't tested. From my test machine, the real CoinGecko API answered 429 (busy shared IP), which the workflow reported instead of crashing. That's the most likely problem you'll hit too if you run n8n on a crowded cloud IP.&lt;/p&gt;

&lt;p&gt;This is information tooling, not financial advice. It reads public prices and can't trade.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disclosure: the paid version
&lt;/h2&gt;

&lt;p&gt;I'm the maker behind Relaybrook, and I also sell a bigger version. The &lt;a href="https://relaybrook.bytesell.app/products/crypto-watch-pack-for-n8n?utm_source=devto" rel="noopener noreferrer"&gt;Crypto Watch Pack for n8n&lt;/a&gt; ($19) adds % move alerts and cooldowns, a daily portfolio report from Google Sheets or CSV, and a watcher that tells you when a public TRON, Ethereum or Bitcoin address receives a transfer (USDT TRC-20 included), all read-only on free public APIs. Code CRYPTO10 takes 10% off until Nov 30, 2026 (crypto checkout). The free workflow above works on its own; you don't need to buy anything.&lt;/p&gt;

</description>
      <category>n8n</category>
      <category>automation</category>
      <category>crypto</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>When 'Cloud Native' Becomes 'Cloud Bloated': Reclaiming Client-Side Power</title>
      <dc:creator>thisran</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:38:41 +0000</pubDate>
      <link>https://dev.to/khaithisran/when-cloud-native-becomes-cloud-bloated-reclaiming-client-side-power-17a</link>
      <guid>https://dev.to/khaithisran/when-cloud-native-becomes-cloud-bloated-reclaiming-client-side-power-17a</guid>
      <description>&lt;p&gt;Recently, a quiet rumble turned into a full-blown roar across the developer community: "Adobe charges $240/yr to rotate a page, and DocuSign charges $480/yr to draw a signature on a PDF." This isn't just a pricing complaint; it's a stark, infuriating symptom of an architectural disease. How did fundamental, trivial operations become gateways to multi-hundred-dollar annual subscriptions, necessitating data round-trips to distant servers and the attendant privacy implications? As software engineers, we need to ask ourselves: Have we collectively adopted a "cloud-first" mindset so uncritically that we've inadvertently built systems where simple utilities are now burdened by layers of authentication, database polling, and billing systems that add zero value to the core function?&lt;/p&gt;

&lt;p&gt;This debate isn't about whether cloud infrastructure is powerful and transformative—it undeniably is. It's about questioning the default impulse, the almost knee-jerk reaction, to put &lt;em&gt;everything&lt;/em&gt; behind a cloud API, even when the task at hand is trivially computable on the client device itself. We've optimized for "scalability" and "managed services" to the point where "rotate a page" implies an AWS Lambda function, an S3 bucket, a DynamoDB table for job status, an API Gateway endpoint, and a Cognito user pool, all before the actual rotation algorithm even runs.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fallacy of Cloud Everything
&lt;/h3&gt;

&lt;p&gt;The appeal of the cloud is undeniable: instant scalability, managed services, reduced operational overhead. For complex, data-intensive, or computationally heavy tasks that truly require distributed processing, the cloud is a game-changer. But for simpler operations, this convenience often comes with hidden, often prohibitive, costs—both monetary and architectural:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Monetary Overhead:&lt;/strong&gt; Every API call, every byte transferred, every millisecond of compute, every bit of storage—it all costs money. These micro-transactions accumulate, turning a simple utility into a significant expense. For our PDF rotation example, the actual computational cost might be fractions of a cent, but the &lt;em&gt;system&lt;/em&gt; cost to manage, secure, and bill for that operation inflates it exponentially.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Architectural Complexity &amp;amp; Latency:&lt;/strong&gt; Introducing a server-side component for client-originating data immediately brings network latency into the equation. Beyond that, you need:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Authentication and Authorization:&lt;/strong&gt; Who is allowed to perform this action? How do we verify their identity and permissions? (OAuth, JWTs, API keys, etc.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Request Validation &amp;amp; Rate Limiting:&lt;/strong&gt; Protecting your API from abuse.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Ingress/Egress:&lt;/strong&gt; Uploading the file, then downloading the processed file. This doubles network traffic and introduces potential points of failure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Job Management:&lt;/strong&gt; For asynchronous tasks, you need mechanisms to track job status, notify the user, and handle failures. (Queueing systems, database polling, webhooks).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling:&lt;/strong&gt; Distributed systems are inherently complex to debug.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Privacy and Security Concerns:&lt;/strong&gt; Every time a user's sensitive document leaves their device and traverses the internet to a third-party server, their privacy is compromised. Even with robust encryption, the data is transiently stored, processed, and managed by another entity. For confidential documents, this is a non-starter. Compliance requirements (GDPR, HIPAA) become significantly more complex when data sovereignty is involved.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Reliance &amp;amp; Offline Limitations:&lt;/strong&gt; A cloud-dependent application is effectively useless without an internet connection. This creates a brittle user experience and fails to leverage the computational resources already available on the user's device.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We've become so accustomed to "serverless" meaning "I don't manage &lt;em&gt;my&lt;/em&gt; servers" that we've forgotten it still means "someone &lt;em&gt;else&lt;/em&gt; manages &lt;em&gt;their&lt;/em&gt; servers, and your data transits them." For operations like rotating a PDF, drawing a signature, or compressing an image, this overhead is not just unnecessary; it's an anti-pattern.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Alternative: Zero-Backend, Air-Gapped Client Computation
&lt;/h3&gt;

&lt;p&gt;What if we could bring the processing back to where the data originates—the user's browser or device? Modern web browsers are incredibly powerful computing environments, equipped with technologies that make complex, CPU-intensive tasks feasible entirely client-side, with zero server interaction.&lt;/p&gt;

&lt;p&gt;The core idea is &lt;strong&gt;air-gapped computation&lt;/strong&gt;: data never leaves the client's memory. The user uploads a file, it's processed locally using Web APIs, and the result is immediately available for download, all without a single byte touching a remote server.&lt;/p&gt;

&lt;p&gt;Key technologies enabling this paradigm shift:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Web Workers:&lt;/strong&gt; These allow JavaScript to run in the background, on a separate thread from the main UI thread. This is crucial for long-running computations (like PDF processing or OCR) to prevent the user interface from freezing, ensuring a smooth and responsive experience.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;WebAssembly (WASM):&lt;/strong&gt; This binary instruction format provides a way to run code written in languages like C, C++, Rust, or Go at near-native speeds directly in the browser. For computationally intensive tasks like parsing PDFs (e.g., PDF.js compiled to WASM) or performing OCR (e.g., Tesseract.js using WASM), WASM offers a significant performance boost over traditional JavaScript, often making previously server-side-only operations viable client-side.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Client-Side Web Crypto API:&lt;/strong&gt; For operations requiring cryptographic security (e.g., signing documents digitally, hashing files, encrypting data), the Web Crypto API provides a secure, browser-native implementation. This ensures that sensitive cryptographic operations remain entirely within the user's device, adhering to strong security principles.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;File System Access API (Progressive Enhancement):&lt;/strong&gt; While not universally supported yet, this API allows web applications to read and write files directly to the user's local file system with their explicit permission, further blurring the lines between web and desktop applications and enhancing offline capabilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By leveraging these powerful browser capabilities, we can build applications that are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Blazing Fast:&lt;/strong&gt; No network latency for processing. Operations execute at the speed of the user's CPU.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Infinitely Scalable (Client-side):&lt;/strong&gt; Each user's browser is its own server. No backend infrastructure to manage or scale for peak loads.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Privacy-First &amp;amp; Secure:&lt;/strong&gt; Data never leaves the user's device. This is a game-changer for sensitive information, offering true air-gapped security.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Truly Offline:&lt;/strong&gt; Once loaded, the application can function perfectly without an internet connection, processing files locally.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Free (to operate):&lt;/strong&gt; Zero server costs for core processing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Real-World Implementation: HandleMyFile - In-Browser Document &amp;amp; PDF Workstation
&lt;/h3&gt;

&lt;p&gt;This architectural critique isn't just theoretical; it's the core philosophy behind &lt;a href="https://handlemyfile.com" rel="noopener noreferrer"&gt;HandleMyFile&lt;/a&gt;, a comprehensive in-browser document and PDF workstation. Our goal was explicit: to liberate users from the exorbitant fees and privacy compromises associated with basic PDF operations. We took the challenge head-on: compress, merge, split, sign, OCR, and convert PDFs &lt;em&gt;without&lt;/em&gt; sending a single byte to a remote cloud server.&lt;/p&gt;

&lt;p&gt;When you use HandleMyFile, your files stay on your machine. All processing happens locally, within your browser. This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;No monthly subscriptions:&lt;/strong&gt; It's absolutely free to use.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Unlimited tasks:&lt;/strong&gt; Process as many files as you need, without arbitrary daily limits.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Uncompromised confidentiality:&lt;/strong&gt; Your sensitive documents never touch our servers. They remain air-gapped in your browser's memory throughout the entire process.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Full offline functionality:&lt;/strong&gt; Once the app is loaded, you can disconnect from the internet and continue working.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our stack leans heavily into the web technologies discussed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Web Workers&lt;/strong&gt; for concurrent, non-blocking PDF processing.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;PDF.js WASM&lt;/strong&gt; (via &lt;code&gt;pdf-lib&lt;/code&gt; and other libraries) for high-performance PDF manipulation.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Client-Side Web Crypto API&lt;/strong&gt; for operations requiring secure signing or hashing.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Tesseract.js WASM&lt;/strong&gt; for fast and accurate Optical Character Recognition (OCR) directly in the browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s a simplified illustration of how a merge operation, for instance, works entirely client-side using &lt;code&gt;pdf-lib&lt;/code&gt;:&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;// Non-blocking Web Worker PDF Processing&lt;/span&gt;
&lt;span class="c1"&gt;// This code runs within a Web Worker to keep the main UI thread responsive.&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'pdf-lib'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Merges multiple PDF files into a single PDF document entirely within the browser.
 *
 * @param {ArrayBuffer[]} pdfBuffers - An array of ArrayBuffers, each representing a PDF file.
 * @returns {Promise&amp;lt;Blob&amp;gt;} A Promise that resolves to a Blob containing the merged PDF.
 */&lt;/span&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;mergePDFsLocally&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdfBuffers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Create a new, empty PDF document to merge into.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;mergedPdf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&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="c1"&gt;// Iterate over each PDF buffer provided by the user.&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="n"&gt;buffer&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;pdfBuffers&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="c1"&gt;// Load the individual PDF document from its buffer.&lt;/span&gt;
      &lt;span class="c1"&gt;// ignoreEncryption: true is useful for handling common forms of encryption&lt;/span&gt;
      &lt;span class="c1"&gt;// that might prevent loading without a password, allowing basic operations.&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ignoreEncryption&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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="c1"&gt;// Copy all pages from the loaded document into the merged document.&lt;/span&gt;
      &lt;span class="c1"&gt;// This is a CPU-intensive operation that happens entirely in the worker.&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;copiedPages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mergedPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;copyPages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPageIndices&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="c1"&gt;// Add the copied pages to the new merged PDF.&lt;/span&gt;
      &lt;span class="n"&gt;copiedPages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;mergedPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&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="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Failed to load or merge a PDF buffer:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="c1"&gt;// Depending on requirements, you might throw, skip, or log this error.&lt;/span&gt;
      &lt;span class="c1"&gt;// For a robust app, you'd communicate this to the user.&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Save the merged PDF document to bytes.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pdfBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mergedPdf&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Return the bytes as a Blob, ready for download by the user.&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pdfBytes&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;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/pdf'&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="c1"&gt;// Example usage (in the main thread, or another worker, sending data to this worker):&lt;/span&gt;
&lt;span class="c1"&gt;// const fileInput = document.getElementById('pdfFiles');&lt;/span&gt;
&lt;span class="c1"&gt;// const pdfFileBuffers = await Promise.all(&lt;/span&gt;
&lt;span class="c1"&gt;//   Array.from(fileInput.files).map(file =&amp;gt; file.arrayBuffer())&lt;/span&gt;
&lt;span class="c1"&gt;// );&lt;/span&gt;
&lt;span class="c1"&gt;// const mergedPdfBlob = await mergePDFsLocally(pdfFileBuffers);&lt;/span&gt;
&lt;span class="c1"&gt;// // Now, 'mergedPdfBlob' can be used to create a download link.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The architecture is elegantly simple compared to its cloud-heavy counterparts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----------------+       +-------------------+       +--------------------+
| User's Browser | ----&amp;gt; | Web Worker Thread | ----&amp;gt; | PDF.js WASM Engine |
| (Main Thread)  |       | (Non-blocking JS) |       | (Native-like Perf) |
+----------------+       +-------------------+       +--------------------+
       | Upload File          | Process File            |
       |                      | (Merge, Split, Rotate,  |
       |                      | Compress, OCR, Sign)    |
       V                      V                         V
+-------------------------------------------------------------+
|                                                             |
|   User's Local Device (RAM, CPU) - No Network I/O (for data)|
|                                                             |
+-------------------------------------------------------------+
       ^
       | Download Processed File
       |
+----------------+
| User's Browser |
| (Main Thread)  |
+----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Contrast this with the typical cloud architecture for a "simple" PDF operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----------------+       +-------------------+       +-----------------+
| User's Browser | ----&amp;gt; | API Gateway / ELB | ----&amp;gt; | AWS Lambda / EC2|
+----------------+       +-------------------+       +-----------------+
       | Upload File          | Authenticate, Rate Limit  | Process File
       |                      |                           | (via Ghostscript,
       |                      |                           | LibreOffice, etc.
       |                      |                           | on server)
       V                      V                           V
+----------------+       +-------------------+       +-----------------+
|   Internet     | ----&amp;gt; |   S3 Bucket       | ----&amp;gt; |   DynamoDB      |
| (Network Latency)|       | (Temporary Storage)|       | (Job Status)    |
+----------------+       +-------------------+       +-----------------+
       ^                      ^                           ^
       | Download Result      | Persist/Retrieve Data     | Update Status
       |                      |                           |
+----------------+       +-------------------+       +-----------------+
| User's Browser | &amp;lt;---- | API Gateway / ELB | &amp;lt;---- | AWS Lambda / EC2|
+----------------+       +-------------------+       +-----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The difference in complexity, data flow, and potential points of failure is staggering.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benchmarking the Paradigm Shift
&lt;/h3&gt;

&lt;p&gt;The real-world benefits become strikingly clear when comparing the client-side approach to traditional SaaS solutions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Commercial SaaS (Adobe / SmallPDF)&lt;/th&gt;
&lt;th&gt;HandleMyFile Client-Side&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Monthly Pricing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;$19.99 / mo per user&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$0.00 Free&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Daily File Limit&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;2 free tasks / 24h&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Unlimited&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Confidentiality&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Stored on AWS S3 buckets&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Air-gapped in client memory&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Offline Support&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Fails without internet&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;✅ 100% Offline functional&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Performance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Network latency + server processing&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Client CPU speed (WASM)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;👉 &lt;strong&gt;Live Tool:&lt;/strong&gt; &lt;a href="https://handlemyfile.com" rel="noopener noreferrer"&gt;https://handlemyfile.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This isn't to say cloud services are always bad. They solve massive problems for large-scale, collaborative, and data-sharing applications. But for granular, single-user utility functions, we've fallen into a trap of over-engineering and over-monetizing simple software.&lt;/p&gt;

&lt;p&gt;As software engineers, we have a responsibility to design systems thoughtfully, balancing the allure of managed services with genuine user needs: privacy, performance, and cost-effectiveness. The capability for powerful client-side computation exists today. It's time we fully embraced it and reclaimed control over fundamental digital tasks.&lt;/p&gt;

&lt;p&gt;What tools or features in your current stack are currently behind a cloud API but could realistically be moved 100% to a zero-backend, client-side implementation using modern web technologies? Have you encountered similar "cloud bloated" scenarios, and how did you approach them?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>webassembly</category>
      <category>privacy</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Java 8 Streams vs Loops: Cleaner Code, Same Complexity?</title>
      <dc:creator>ayesha azhar</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:38:29 +0000</pubDate>
      <link>https://dev.to/ayeshaazhar/java-8-streams-vs-loops-cleaner-code-same-complexity-5eci</link>
      <guid>https://dev.to/ayeshaazhar/java-8-streams-vs-loops-cleaner-code-same-complexity-5eci</guid>
      <description>&lt;p&gt;Most Java developers have written hundreds of for loops that filter, transform, and group data. They work, but they bury the intent of the code under boilerplate. Java 8’s Stream API lets you describe what you want instead of how to get it. But how do streams compare with loops in performance? Let’s look at both readability and time complexity.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;From Loop to Stream&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Suppose we need the total revenue of completed orders over $100, grouped by customer. The classic approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;revenueByCustomer&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;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;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="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;orders&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="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;COMPLETED&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTotal&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="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="n"&gt;revenueByCustomer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getCustomerName&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="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTotal&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="kt"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;sum&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the stream version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;revenueByCustomer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stream&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="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;COMPLETED&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTotal&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="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="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;groupingBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;getCustomerName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;summingDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;getTotal&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pipeline reads like a sentence: keep completed orders, keep large ones, group by customer, sum the totals. There is no mutable state to track.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;How Pipelines Work&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
A stream pipeline has a source, zero or more intermediate operations (filter, map, sorted), and one terminal operation (collect, reduce, findFirst). Intermediate operations are lazy: nothing runs until the terminal operation is called. This enables short-circuiting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;hasLargeOrder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stream&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="nf"&gt;anyMatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTotal&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="mi"&gt;10_000&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;If the first order qualifies, the remaining elements are never examined.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Useful Collectors&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
partitioningBy splits data into two groups, and joining builds strings without a manual StringBuilder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;split&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stream&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="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;partitioningBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTotal&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="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="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stream&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="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;getCustomerName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;distinct&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="nf"&gt;sorted&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="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;joining&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="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Time Complexity: Streams vs Loops&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is the key point: streams do not change the Big-O complexity of your algorithm. Filtering, mapping, and summing a collection is O(n) whether you use a loop or a stream.&lt;/p&gt;

&lt;p&gt;A common misconception is that chaining several operations creates several passes over the data. It doesn’t. Streams process elements one at a time through the whole pipeline (called loop fusion), so filter().map().filter() is still a single O(n) traversal.&lt;/p&gt;

&lt;p&gt;The complexity of individual operations matters, though:&lt;/p&gt;

&lt;p&gt;filter, map, forEach, reduce: O(n)&lt;br&gt;
distinct: O(n) on average, since it uses a hash set internally&lt;br&gt;
sorted: O(n log n)&lt;br&gt;
groupingBy with the default HashMap: O(n) on average&lt;br&gt;
anyMatch, findFirst, limit: O(1) best case, O(n) worst case, thanks to short-circuiting&lt;/p&gt;

&lt;p&gt;Where streams can hurt is hidden complexity. This code looks harmless but is O(n × m):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;matches&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stream&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="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;blockedIds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getCustomerId&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="c1"&gt;// List.contains is O(m)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toList&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If blockedIds is a List, every order triggers a linear scan. Converting it to a HashSet first brings the whole operation down to O(n + m):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;blocked&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;HashSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blockedIds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;matches&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stream&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="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;blocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getCustomerId&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="c1"&gt;// O(1) on average&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toList&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On constant factors, loops usually win slightly. Streams add lambda and iterator overhead, and Stream boxes primitives. For small collections or hot paths, a plain loop (or IntStream to avoid boxing) can be faster. For typical business code, the difference is negligible, so measure with a tool like JMH before optimizing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros and Cons of Streams&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Readability: the code expresses intent, not mechanics.&lt;br&gt;
Less mutable state: fewer bugs from forgotten variables or off-by-one errors.&lt;br&gt;
Composability: operations chain and refactor easily.&lt;br&gt;
Easy parallelism: parallelStream() can speed up CPU-heavy work on large datasets.&lt;br&gt;
Lazy evaluation: short-circuiting avoids unnecessary work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Overhead: slightly slower than loops on small or primitive-heavy workloads.&lt;br&gt;
Harder debugging: stack traces through lambdas are less direct.&lt;br&gt;
Hidden complexity: an expensive call inside a lambda is easy to miss.&lt;br&gt;
Limited control flow: no easy way to break, continue, or throw checked exceptions.&lt;br&gt;
Single use: a stream can’t be reused after a terminal operation.&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Streams and loops share the same algorithmic complexity, so choose between them based on clarity, not speed. Use streams for transformations, filtering, and grouping. Stick with loops for performance-critical inner code, complex control flow, or in-place modification. Whichever you choose, always watch the cost of what happens inside the pipeline, because that’s where real performance problems hide.&lt;/p&gt;

</description>
      <category>java</category>
      <category>streamvsloops</category>
    </item>
    <item>
      <title>Is it cheaper to book directly with the hotel? I checked 23 hotels in 5 cities</title>
      <dc:creator>Monkey.D.Scraping</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:38:19 +0000</pubDate>
      <link>https://dev.to/monkeydscraping/is-it-cheaper-to-book-directly-with-the-hotel-i-checked-23-hotels-in-5-cities-35gc</link>
      <guid>https://dev.to/monkeydscraping/is-it-cheaper-to-book-directly-with-the-hotel-i-checked-23-hotels-in-5-cities-35gc</guid>
      <description>&lt;p&gt;"Book direct, it's always cheaper" is one of those travel tips everyone repeats. Hotels push it, OTAs push the opposite. I had the data to check it, so I did.&lt;/p&gt;

&lt;p&gt;Disclosure: the data comes from a Google Hotels scraper I built and sell on Apify, and an AI assistant helped me draft this post. The numbers are from runs I did on November 17, 2026.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;5 cities: Rome, Paris, London, Barcelona, New York&lt;/li&gt;
&lt;li&gt;Same stay everywhere: January 15–17, 2027, 2 adults, prices in USD&lt;/li&gt;
&lt;li&gt;The top 20 hotels Google Hotels shows for each city, with every room offer it lists per booking site&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's 100 hotels. 85 had room offers. &lt;strong&gt;23 had both an offer from the hotel's own website and at least one from a booking site&lt;/strong&gt; (Booking.com, Expedia, Hotels.com, Travelocity, Priceline, Agoda and a few others). Those 23 are the sample.&lt;/p&gt;

&lt;p&gt;For each hotel I compared the cheapest total on the official site with the cheapest total on any booking site.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is it cheaper to book directly with the hotel?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;th&gt;Hotels&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Official site cheaper&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same price&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Booking site cheaper&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Basically a three-way split. The median difference was exactly 0%.&lt;/p&gt;

&lt;p&gt;The gaps were not small when they existed:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Hotel&lt;/th&gt;
&lt;th&gt;City&lt;/th&gt;
&lt;th&gt;Official site&lt;/th&gt;
&lt;th&gt;Cheapest booking site&lt;/th&gt;
&lt;th&gt;Difference&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Paramount Times Square&lt;/td&gt;
&lt;td&gt;New York&lt;/td&gt;
&lt;td&gt;$349&lt;/td&gt;
&lt;td&gt;$436 (Travelocity)&lt;/td&gt;
&lt;td&gt;−20%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Petit Palace Boqueria Garden&lt;/td&gt;
&lt;td&gt;Barcelona&lt;/td&gt;
&lt;td&gt;$273&lt;/td&gt;
&lt;td&gt;$335 (Expedia)&lt;/td&gt;
&lt;td&gt;−19%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Premier Inn London Woolwich&lt;/td&gt;
&lt;td&gt;London&lt;/td&gt;
&lt;td&gt;$148&lt;/td&gt;
&lt;td&gt;$179 (Expedia)&lt;/td&gt;
&lt;td&gt;−17%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;H10 Montcada&lt;/td&gt;
&lt;td&gt;Barcelona&lt;/td&gt;
&lt;td&gt;$293&lt;/td&gt;
&lt;td&gt;$351 (Hotels.com)&lt;/td&gt;
&lt;td&gt;−17%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Crowne Plaza Paris République&lt;/td&gt;
&lt;td&gt;Paris&lt;/td&gt;
&lt;td&gt;$469&lt;/td&gt;
&lt;td&gt;$401 (goseek)&lt;/td&gt;
&lt;td&gt;+17%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Kimpton Fitzroy&lt;/td&gt;
&lt;td&gt;London&lt;/td&gt;
&lt;td&gt;$778&lt;/td&gt;
&lt;td&gt;$638 (dealbase)&lt;/td&gt;
&lt;td&gt;+22%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The Cumberland&lt;/td&gt;
&lt;td&gt;London&lt;/td&gt;
&lt;td&gt;$399&lt;/td&gt;
&lt;td&gt;$322 (dealbase)&lt;/td&gt;
&lt;td&gt;+24%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Life Hotel&lt;/td&gt;
&lt;td&gt;New York&lt;/td&gt;
&lt;td&gt;$508&lt;/td&gt;
&lt;td&gt;$406 (Booking.com)&lt;/td&gt;
&lt;td&gt;+25%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So "always book direct" is wrong about a third of the time, and "OTAs are always cheaper" is wrong about two thirds of the time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Booking direct or Booking.com, Expedia: what the pattern looks like
&lt;/h2&gt;

&lt;p&gt;A few things stood out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Chains with their own booking engines often matched or beat the OTAs.&lt;/strong&gt; H10, Premier Inn, NH Collection, Novotel, Hyatt, DoubleTree were either cheaper direct or exactly the same.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When an OTA won by a lot, it was often a smaller seller&lt;/strong&gt; (dealbase, goseek) rather than Booking.com or Expedia.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Same price on many sites is common.&lt;/strong&gt; That's hotel rate parity in action: many contracts ask the hotel to show the same rate everywhere.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One honest caveat on method: room names are written differently on each site, so I compared the cheapest offer of any room, not the identical room. Two rooms called "Standard Double" and "Classic Room" may not be the same product.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is hotel rate parity, and how do you check it?
&lt;/h2&gt;

&lt;p&gt;Rate parity means a hotel shows the same price for the same room on its own site and on every OTA. Revenue managers check it daily, because a cheaper OTA steals direct bookings (and the hotel pays it a commission), while a cheaper direct rate can break a contract.&lt;/p&gt;

&lt;p&gt;Checking it by hand means opening a dozen tabs per hotel per date. Checking it with code is one call:&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;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;apify_client&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ApifyClient&lt;/span&gt;

&lt;span class="no"&gt;OTAS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Hotels.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Expedia.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Travelocity.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Booking.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"Priceline"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Agoda"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Trip.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"dealbase.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"goseek.com"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ApifyClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"APIFY_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;actor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"monkey.d.scraping/google-hotels-room-offers"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;run_input&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"hotels"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"H10 Montcada Barcelona"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Hotel Catalonia Ramblas Barcelona"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"checkIn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2027-01-15"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"checkOut"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2027-01-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"currency"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"USD"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"maxOffersPerHotel"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&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="n"&gt;offers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;default_dataset_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;iterate_items&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;for&lt;/span&gt; &lt;span class="n"&gt;hotel&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"hotelName"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;offers&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="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;offers&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"hotelName"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;hotel&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;direct&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"stayTotalDisplayed"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"provider"&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="no"&gt;OTAS&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;ota&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"provider"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;OTAS&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;direct&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;ota&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;best&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;ota&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"stayTotalDisplayed"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;gap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&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;direct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;best&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"stayTotalDisplayed"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;best&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"stayTotalDisplayed"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{hotel}: direct ${min(direct):.0f} vs {best['provider']} ${best['stayTotalDisplayed']:.0f} ({gap:+.0%})"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each offer row also carries the room name, nightly price, free cancellation, cancellation deadline and breakfast when the site states them, so you can compare like for like before shouting "parity breach".&lt;/p&gt;

&lt;p&gt;The five-city run cost about $0.18 in total. Schedule it daily on Apify and you have a free-ish rate parity checker.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, should you book direct?
&lt;/h2&gt;

&lt;p&gt;Check both, every time. In my sample the two options were a coin flip with a third side. If you're a traveller: compare the official site with the cheapest OTA for your exact dates. If you run a hotel: someone is probably doing this to you already.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Is it cheaper to book directly with the hotel or Booking.com?&lt;/strong&gt; In this sample, the official site was cheaper in 8 of 23 hotels, the same in 8 and more expensive in 7. It depends on the hotel and the date.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What does rate parity mean in hotels?&lt;/strong&gt; The same room at the same price on the hotel website and on every online travel agency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do I check rate parity automatically?&lt;/strong&gt; Collect the offers per booking site for your hotels and dates (the script above), then compare the official site with the cheapest OTA.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where does the data come from?&lt;/strong&gt; Google Hotels, which lists the price each booking site quotes for a hotel. I use my &lt;a href="https://apify.com/monkey.d.scraping/google-hotels-room-offers" rel="noopener noreferrer"&gt;Google Hotels API on Apify&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want the raw numbers for a city, ask in the comments and I'll run it.&lt;/p&gt;

</description>
      <category>travel</category>
      <category>python</category>
      <category>datascience</category>
      <category>webscraping</category>
    </item>
    <item>
      <title>Why ActLike AI Bills Video by the Rendered Second, and Builds Consent Into the Flow</title>
      <dc:creator>ActLike AI</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:38:04 +0000</pubDate>
      <link>https://dev.to/actlike_ai_70f7af77924e9b/why-actlike-ai-bills-video-by-the-rendered-second-and-builds-consent-into-the-flow-5a9</link>
      <guid>https://dev.to/actlike_ai_70f7af77924e9b/why-actlike-ai-bills-video-by-the-rendered-second-and-builds-consent-into-the-flow-5a9</guid>
      <description>&lt;p&gt;While we built &lt;a href="https://actlikeai.video/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=home" rel="noopener noreferrer"&gt;ActLike AI&lt;/a&gt; (actlikeai.video), two questions kept coming back. How should a video product charge when every output is a different length? And where should rules about consent go in a tool that puts a real person into a clip?&lt;/p&gt;

&lt;p&gt;This post covers how we answered both, as product decisions only. If you build with paid AI generation, you may face the same trade-offs.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ActLike AI?
&lt;/h2&gt;

&lt;p&gt;ActLike AI is a web and iPhone tool that puts you, or someone who agreed, into a short clip or viral trend from one photo. It replaces the whole person (face, hair, body and clothing) and keeps the clip's motion, camera and sound.&lt;/p&gt;

&lt;p&gt;You can use it in the browser through the web studio, or in the iPhone app. Both use one account and one credit balance. On Android, you use the browser.&lt;/p&gt;

&lt;p&gt;You can bring your own clip (MP4 or MOV; one continuous shot with one person clearly in frame works best), or pick a trend. Each trend has one fixed role. Examples include Seaside Arrival, where you step out of a red convertible by the sea at night (11 s), and Gentleman Move, the bushes meme where a man steps into a hedge (9 s).&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with a flat price per video
&lt;/h2&gt;

&lt;p&gt;Video output does not come in one size. A 9-second trend and a 30-second road-trip clip are very different jobs, yet a flat per-video price treats them as the same. A flat price leaves two bad options: short clips pay for long ones, or the price is set for the longest clip and feels expensive to everyone else.&lt;/p&gt;

&lt;p&gt;A subscription had its own problem. Someone who wants one video for one trend should not have to keep a monthly charge running between videos. We did not want to ask for that.&lt;/p&gt;

&lt;p&gt;So we tied the price to the two things that really change the work: how many seconds get rendered, and at what resolution.&lt;/p&gt;

&lt;h2&gt;
  
  
  The credit rule
&lt;/h2&gt;

&lt;p&gt;The rule fits in three lines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;480p (Credit Saver):&lt;/strong&gt; 1 credit per second&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;720p HD (Best Quality):&lt;/strong&gt; 2 credits per second&lt;/li&gt;
&lt;li&gt;Seconds are counted as whole seconds, rounded up&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rounding up to the next whole second keeps the number easy to predict. You can work out the cost in your head before you press render.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worked examples
&lt;/h2&gt;

&lt;p&gt;Here is the math in a few common cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A 10-second clip of your own at 480p&lt;/strong&gt; uses 10 credits. The same clip at 720p uses 20 credits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A 10.4-second clip&lt;/strong&gt; counts as 11 seconds. That is 11 credits at 480p or 22 at 720p.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A draft, then a final:&lt;/strong&gt; you render a 10-second clip at 480p to check the result (10 credits), then render it again at 720p (20 credits). The total is 30 credits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A trend&lt;/strong&gt; costs what its trend page shows. Gentleman Move is 9 seconds, so it costs 9 credits at 480p.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The 480p Credit Saver option is there for that draft-then-final pattern. It gives you a cheaper test render before you spend more on the HD version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Packs, not a subscription
&lt;/h2&gt;

&lt;p&gt;On the web, credits come in one-time card packs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Credits&lt;/th&gt;
&lt;th&gt;Price&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;$3.49&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;$11.49&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;$15.99&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;250&lt;/td&gt;
&lt;td&gt;$30.99&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;td&gt;$44.99&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;There is no subscription. Credits do not expire while your account is open, so a pack bought for one trend still works for the next. Unused web packs can be refunded within 14 days. The point was to make buying credits a small decision you can undo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failed renders return their credits
&lt;/h2&gt;

&lt;p&gt;AI rendering sometimes fails. Charging people for output they never got would hurt trust quickly, so a failed video returns its credits automatically. You do not need to open a ticket or ask.&lt;/p&gt;

&lt;p&gt;We also try to stop failures before they cost anything. A photo check flags dark, blurry or turned-away photos before any credits are spent. The photo tips are simple: one clear, front-facing photo of you alone, in even light, with no sunglasses and no hands over the face. Your clothes come from the photo too, so for trends that show you head to toe, use a full-body photo.&lt;/p&gt;

&lt;p&gt;The order of steps follows the same idea. Guests can set up everything in the web studio without an account. Sign-in and payment happen only at render time, and nothing renders before you pay with credits. Renders usually take a few minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consent and AI labels are part of the flow
&lt;/h2&gt;

&lt;p&gt;A tool that replaces the person in a video needs clear rules, and we wanted those rules in the product, not hidden in a policy page:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use only your own photos, or photos of people who agreed.&lt;/li&gt;
&lt;li&gt;No public figures.&lt;/li&gt;
&lt;li&gt;Nobody under 18. Web accounts are 18+.&lt;/li&gt;
&lt;li&gt;No sexual content, and no use to deceive or impersonate anyone.&lt;/li&gt;
&lt;li&gt;Every result is AI-generated. Post it with the platform's AI label.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We see the AI label as part of using the result correctly. The product makes something that looks real, and people who watch it should know what they are seeing.&lt;/p&gt;

&lt;p&gt;Privacy is part of the same thinking. Uploaded media is normally deleted automatically within about 3 days. The site also has a trust page that answers whether ActLike AI is legit and covers these points. ActLike AI is not affiliated with actlike.me, which is a different product.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we would tell other makers
&lt;/h2&gt;

&lt;p&gt;If your AI product produces output of different sizes, try pricing by the unit that really changes, and make the math simple enough to do in your head. Return credits for failures without being asked. Put your usage rules where people make decisions, not only in the footer.&lt;/p&gt;

&lt;p&gt;If you want to see how this works in practice, open &lt;a href="https://actlikeai.video/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=home" rel="noopener noreferrer"&gt;ActLike AI&lt;/a&gt;. Set up a clip as a guest, check the credit cost on screen, and render only when it looks right.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is ActLike AI?&lt;/strong&gt;&lt;br&gt;
It is a web and iPhone tool that puts you, or someone who agreed, into a short clip or viral trend from one photo, replacing the whole person while the clip's motion, camera and sound stay.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How much does an ActLike AI video cost?&lt;/strong&gt;&lt;br&gt;
A clip of your own costs 1 credit per second at 480p or 2 credits per second at 720p, counted in whole seconds and rounded up. A 10-second 480p video uses 10 credits. A trend costs what its trend page shows. Web packs start at 15 credits for $3.49, and there is no subscription.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens if a render fails?&lt;/strong&gt;&lt;br&gt;
The credits for a failed video go back to your balance automatically. A photo check also flags dark, blurry or turned-away photos before any credits are spent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I use a photo of someone else?&lt;/strong&gt;&lt;br&gt;
Only if that person agreed. Public figures and anyone under 18 are not allowed. Results are AI-generated and should be posted with the platform's AI label.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do I contact ActLike AI?&lt;/strong&gt;&lt;br&gt;
Email &lt;code&gt;support@actlikeai.video&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>video</category>
      <category>webdev</category>
    </item>
    <item>
      <title>That checksum next to the download button is a promise. Here is how to check it kept it</title>
      <dc:creator>Mubeen Khan</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:36:34 +0000</pubDate>
      <link>https://dev.to/mubeenkhaaan/that-checksum-next-to-the-download-button-is-a-promise-here-is-how-to-check-it-kept-it-185g</link>
      <guid>https://dev.to/mubeenkhaaan/that-checksum-next-to-the-download-button-is-a-promise-here-is-how-to-check-it-kept-it-185g</guid>
      <description>&lt;p&gt;You have seen the string. It sits next to the download button on every serious software page: a 64-character jumble of letters and numbers, labelled SHA-256, with no explanation of what you are supposed to do with it.&lt;/p&gt;

&lt;p&gt;It is a promise. The publisher is saying: this file, exactly as we built it, hashes to this value. If the file you downloaded hashes to something else, it is not the file they built. Something changed it on the way to you. Maybe a flaky connection corrupted a byte. Maybe worse.&lt;/p&gt;

&lt;p&gt;A hash function takes any input, of any size, and returns a fixed-length fingerprint. Feed it the same bytes and you always get the same fingerprint. Change one single byte, a comma in a config file, one pixel in an image, and the fingerprint changes completely. That avalanche effect is the whole point. You do not compare a 400 MB installer byte by byte. You compare two short strings.&lt;/p&gt;

&lt;p&gt;The part most people get wrong is which algorithm to trust. MD5 is the old famous one, 32 hex characters, and it is broken. Researchers can craft two different files with the same MD5 fingerprint, which means an MD5 match proves almost nothing about authenticity today. SHA-1 is in the same boat: deprecated since 2011, and a real collision was demonstrated in 2017. Both are fine for catching an accidental download error, and neither should guard anything that matters.&lt;/p&gt;

&lt;p&gt;SHA-256 is the everyday default now. 64 hex characters, no practical attacks, and the same algorithm behind TLS certificates, Git's newer object format, and Bitcoin. When a download page offers a checksum, it is almost always SHA-256, and it is worth the ten seconds to check it.&lt;/p&gt;

&lt;p&gt;Checking it does not need a terminal, and it does not need you to upload the file anywhere. Your browser already has the machinery built in. The Web Crypto API, the same code your browser uses for TLS, computes SHA-1, SHA-256, SHA-384 and SHA-512 natively. MD5 is the odd one out: browsers never shipped it, so a page that offers MD5 has to carry its own small implementation of the 1992 RFC. That is the only reason MD5 still shows up on hash pages at all.&lt;/p&gt;

&lt;p&gt;Here is the workflow that actually works. Download the file. Open a hash generator that runs entirely in your browser and drop the file in. It computes the hashes locally, nothing is uploaded, and you compare the SHA-256 row against the string the publisher printed. Match means the file is intact. Mismatch means download it again, from the official source, and if it mismatches twice, stop and ask the publisher. A free hash generator that does text and files, with a compare mode that tells you match or no match instead of making you eyeball two 64-character strings, is the one I keep bookmarked for this. I use the one on The Utility Hub for exactly this check, and it also does HMAC when a service hands you a signing key instead of a plain checksum: &lt;a href="https://www.theutilityhub.online/tools/hash-generator" rel="noopener noreferrer"&gt;https://www.theutilityhub.online/tools/hash-generator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two habits make the check real. First, always verify against the checksum published on the official site, never one pasted in a forum comment or a random mirror. If the mirror is compromised, its checksum is compromised too. Second, remember what a hash is not. It is one-way: you cannot reverse a hash back into the file, which is why hashed passwords are safer than stored ones. And a hash tells you the file is unchanged, not that it is safe. A perfectly intact file can still be malware if the publisher was compromised. Hashing proves integrity, not trust.&lt;/p&gt;

&lt;p&gt;The string next to the download button is not decoration. It is the publisher handing you a way to catch a broken or tampered download before you run it. Ten seconds, one comparison, and you know the file you have is the file they built.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>security</category>
    </item>
    <item>
      <title>Donchian Channel Strategy: Breakouts, False Signals and Bollinger Bands</title>
      <dc:creator>AlgoRover</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:36:30 +0000</pubDate>
      <link>https://dev.to/algorover/donchian-channel-strategy-breakouts-false-signals-and-bollinger-bands-lhj</link>
      <guid>https://dev.to/algorover/donchian-channel-strategy-breakouts-false-signals-and-bollinger-bands-lhj</guid>
      <description>&lt;span&gt;Strategy Analysis&lt;/span&gt; &lt;p&gt;A channel touch is not a complete trading rule. Follow entry, holding and exit, compare Bollinger Bands, and inspect what happens after a closing signal.&lt;/p&gt;   &lt;p&gt;A price breaks its recent high, you buy, and it drops straight back into the range. That is the uncomfortable part of a Donchian channel strategy: did a trend just start, or did you buy another false breakout?&lt;/p&gt; &lt;p&gt;&lt;strong&gt;A Donchian channel gives “the recent high” a precise definition. It does not tell you that the next move will keep rising.&lt;/strong&gt; To test the strategy, you also need a reference window, a confirmation time, an entry order and an exit rule.&lt;/p&gt; &lt;p&gt;Start by connecting those decisions. Then the difference between Donchian channels and Bollinger Bands becomes useful, rather than just another comparison of indicator names.&lt;/p&gt; &lt;h2&gt;What is a Donchian channel?&lt;/h2&gt; &lt;p&gt;For a 20-period channel, the upper boundary is the highest high in the window, the lower boundary is its lowest low, and the middle is halfway between them. On a four-hour chart, 20 bars span 80 hours. They do not mean 20 days.&lt;/p&gt; &lt;p&gt;Suppose 20 completed candles have a high of 104 USDT and a low of 94 USDT. Their channel boundaries are 104 and 94, with a midpoint of 99. That midpoint is not the average closing price. These are assumed prices used below to follow the timing of one trade.&lt;/p&gt; &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstorage.ghost.io%2Fc%2F6d%2Fbb%2F6dbbb7cc-1f93-4cd3-8d75-e3c2cfce055f%2Fcontent%2Fimages%2F2026%2F11%2Fdonchian-three-lines-en-a98eb363a202.png" alt="Twenty assumed four-hour candles: candle 18 sets the highest high of 104, candle 5 sets the lowest low of 94, and equal-length arrows place the middle at 99 halfway between the two boundaries." width="800" height="700"&gt;Read this assumed window at the close of candle 20. The circled high and low set the boundaries; two equal-length arrows locate their midpoint. As the window moves forward, all three levels are recalculated from the new window. &lt;p&gt;&lt;span&gt;TradingView documents the channel calculation&lt;/span&gt;. Turning it into an executable breakout rule introduces another choice: which bars go into the comparison?&lt;/p&gt; &lt;h2&gt;Donchian breakout strategy: exclude the signal candle&lt;/h2&gt; &lt;p&gt;If the current candle is included in the channel maximum, its close cannot be strictly above that maximum: an ordinary candle cannot close above its own high. A rule requiring a close above that current-window upper boundary can therefore remain silent indefinitely.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;For a close-confirmed breakout, calculate the high of the previous 20 completed candles, then compare the current close against it.&lt;/strong&gt; Check whether the plotted indicator includes the current bar or uses an offset. The chart and the strategy must reference the same window.&lt;/p&gt; &lt;p&gt;In the assumed sequence, candle 21 reaches 106 but closes at 103. It trades through the previous high of 104, yet does not pass the close-confirmed entry rule. Before candle 22, the reference high has risen to 106. A close at 107 then qualifies.&lt;/p&gt; &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstorage.ghost.io%2Fc%2F6d%2Fbb%2F6dbbb7cc-1f93-4cd3-8d75-e3c2cfce055f%2Fcontent%2Fimages%2F2026%2F11%2Fdonchian-breakout-en-2.png" alt="Assumed four-hour candles: candle 21 wicks above the previous 20-bar high but closes below it; candle 22 closes at 107 above the reference high of 106, followed by an assumed entry at 107.5." width="800" height="500"&gt;Assumed prices, four hours per candle. The dashed threshold uses only the previous 20 completed bars. A wick above the threshold and a confirmed closing breakout happen at different times. &lt;h2&gt;Follow one trade from entry to exit&lt;/h2&gt; &lt;p&gt;Here is a defined starting rule for a spot, long-only strategy. It is not presented as the full historical Turtle Trading system.&lt;/p&gt; &lt;ul&gt;
&lt;li&gt;While flat, record an entry signal when the close is strictly above the high of the previous 20 bars.&lt;/li&gt;
&lt;li&gt;Submit the buy at the beginning of the next bar. The walkthrough assumes a fill at that opening price; actual execution needs a separate check.&lt;/li&gt;
&lt;li&gt;Hold one position without adding to it or buying again while already invested.&lt;/li&gt;
&lt;li&gt;Record an exit when the close is strictly below the low of the previous 10 bars. Submit the sell at the beginning of the next bar.&lt;/li&gt;
&lt;li&gt;A close exactly equal to either threshold does not meet these strict comparisons.&lt;/li&gt;
&lt;/ul&gt; &lt;p&gt;Suppose you buy one unit at 107.5 USDT on candle 23, following candle 22's signal. Price later reaches 112. You keep holding because this rule does not take profit at a fixed percentage.&lt;/p&gt; &lt;p&gt;Price then falls. The 10 completed candles before candle 28 have a low of 100. Candle 28 closes at 99 and produces an exit signal. If the next candle opens and fills at 98.5, the trade loses 9 USDT before fees. An earlier unrealized profit did not become a realized gain.&lt;/p&gt; &lt;div class="table-wrapper-paragraph"&gt;When the assumed trade makes each decision&lt;table&gt;&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;Time&lt;/th&gt;
&lt;th&gt;Comparison&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Candle 21 close&lt;/td&gt;
&lt;td&gt;103 is not above the prior high of 104&lt;/td&gt;
&lt;td&gt;No entry; a wick to 106 is not closing confirmation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Candle 22 close&lt;/td&gt;
&lt;td&gt;107 is above the prior high of 106&lt;/td&gt;
&lt;td&gt;Record the signal; wait for the next bar to submit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Candle 23 open&lt;/td&gt;
&lt;td&gt;Assumed fill at 107.5&lt;/td&gt;
&lt;td&gt;Buy one unit; do not pyramid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Candle 28 close to candle 29 open&lt;/td&gt;
&lt;td&gt;99 is below the prior low of 100&lt;/td&gt;
&lt;td&gt;Record the exit; assume a sale at 98.5 next bar&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt; &lt;p&gt;The strategy needs some breakouts to continue far enough to offset failed attempts. A close-based exit also leaves exposure to intrabar declines and gaps into the next bar. Adding a fixed or ATR-based stop changes the rule set and needs its own test.&lt;/p&gt; &lt;h2&gt;When does a Donchian channel strategy make sense?&lt;/h2&gt; &lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;✅ Sustained directional moves:&lt;/strong&gt; new highs continue to be followed by new highs, allowing the position to remain open.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;⚠️ A fast surge followed by a sharp reversal:&lt;/strong&gt; closing confirmation and next-bar submission can enter late, while the exit gives back an unrealized gain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;❌ Repeated breaks around a narrow range:&lt;/strong&gt; price exceeds the boundary, retreats, then repeats. Entries, exits and fees can accumulate without a lasting trend.&lt;/li&gt;
&lt;/ul&gt; &lt;p&gt;Include the false breaks and long waiting periods in the review. Selecting a few attractive breakout charts leaves out much of the strategy's experience.&lt;/p&gt; &lt;h2&gt;Donchian channel settings: what changes between 20 and 55?&lt;/h2&gt; &lt;p&gt;Keep the asset, four-hour timeframe, order logic and costs constant. Change the entry and exit lengths separately. The 20/10 pair below is this article's defined rule, not an optimized setting.&lt;/p&gt; &lt;div class="table-wrapper-paragraph"&gt;Changing the window changes the threshold&lt;table&gt;&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Shorter window&lt;/th&gt;
&lt;th&gt;Article rule&lt;/th&gt;
&lt;th&gt;Longer window&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Entry lookback&lt;/td&gt;
&lt;td&gt;10 bars: high of the previous 40 hours&lt;/td&gt;
&lt;td&gt;20 bars: high of the previous 80 hours&lt;/td&gt;
&lt;td&gt;55 bars: high of the previous 220 hours&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exit lookback&lt;/td&gt;
&lt;td&gt;5 bars: a more recent low, potentially a higher sell threshold&lt;/td&gt;
&lt;td&gt;10 bars: low of the previous 40 hours&lt;/td&gt;
&lt;td&gt;20 bars: an older low may allow more of the move to be given back&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt; &lt;p&gt;At the same instant, a longer entry window cannot have a lower maximum than its shorter subset. A longer exit window cannot have a higher minimum. How those differences affect total trades and net returns depends on the full path, including the changing position state.&lt;/p&gt; &lt;h2&gt;Donchian channel vs Bollinger Bands: the same touch means different things&lt;/h2&gt; &lt;p&gt;Donchian channels ask whether price has exceeded a recent extreme. Traditional Bollinger Bands measure price relative to an average of closes and their standard deviation. Their upper boundaries can be at very different prices.&lt;/p&gt; &lt;p&gt;A large wick can keep a Donchian high elevated until that bar leaves the window. Bollinger Bands instead change with the distribution of closing prices in their window.&lt;/p&gt; &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstorage.ghost.io%2Fc%2F6d%2Fbb%2F6dbbb7cc-1f93-4cd3-8d75-e3c2cfce055f%2Fcontent%2Fimages%2F2026%2F11%2Fdonchian-bollinger-en-1.png" alt="The same assumed closes compared with the previous 20-bar Donchian high and a Bollinger upper band calculated from the prior 20 closes, showing different entry thresholds." width="800" height="500"&gt;The same assumed market sequence. For signal comparison, both upper boundaries use the previous 20 completed candles. Bollinger uses SMA 20 plus two population standard deviations of closes. &lt;p&gt;That does not create a universal “buy at the Donchian upper band, sell at the Bollinger upper band” rule. &lt;span&gt;John Bollinger's own rules&lt;/span&gt; explain that an upper-band tag alone is not a sell signal; price can travel along the band in a trend.&lt;/p&gt; &lt;p&gt;Compare complete strategies: entry, exit, confirmation time, costs and execution assumptions. Changing several of those while changing the indicator makes the source of any performance difference hard to identify.&lt;/p&gt; &lt;h2&gt;What to check in a Donchian channel backtest&lt;/h2&gt; &lt;p&gt;Find a wick-only break and check that the strategy waits if closing confirmation is required. Then inspect a confirmed entry and the bars used for its reference high. Follow the order into the next candle rather than treating the signal close as a guaranteed execution price.&lt;/p&gt; &lt;p&gt;Use the same rule set through both trends and choppy ranges. Review trade count, losing streaks, drawdown and results after costs. &lt;span&gt;Check that an AI-generated strategy follows your rules&lt;/span&gt; before tuning the lookback. Candle lows alone cannot establish the order of events or prove that an order filled.&lt;/p&gt; &lt;p&gt;AlgoRover Research can help you find published strategies and their available historical-test configurations. Read a candidate's actual rules first: sharing the Donchian name does not establish identical windows, exits or sizing.&lt;/p&gt; &lt;h2&gt;Frequently asked questions&lt;/h2&gt; &lt;h3&gt;Should I enter a Donchian breakout immediately or wait for the close?&lt;/h3&gt; &lt;p&gt;Both can define a strategy, but they accept different trades. This article waits for the close and submits next bar. Switching to an intrabar touch includes temporary wick breaks, so the close-confirmed test results no longer describe the same strategy.&lt;/p&gt; &lt;h3&gt;Does a 20-period Donchian channel always mean 20 days?&lt;/h3&gt; &lt;p&gt;No. It means 20 bars of the selected timeframe: 80 hours on four-hour candles, or 20 daily bars on a daily chart.&lt;/p&gt; &lt;h3&gt;Can Donchian channels eliminate false breakouts?&lt;/h3&gt; &lt;p&gt;No. Confirmation and trend filters change which signals qualify, while also excluding some winning trades. Evaluate both sides of that change.&lt;/p&gt; &lt;h3&gt;Are Donchian channels better than Bollinger Bands?&lt;/h3&gt; &lt;p&gt;They answer different questions about extremes and dispersion around an average. A return comparison needs complete rules tested on the same market, period and execution conditions.&lt;/p&gt;  &lt;h2&gt;Use AlgoRover Live to inspect the next-bar orders&lt;/h2&gt; &lt;p&gt;The next useful question is what happens after a closing signal. With &lt;span&gt;AlgoRover Live&lt;/span&gt;, you can run a confirmed strategy in a supported exchange Demo environment and inspect orders, fills and positions, connecting signal timing with execution.&lt;/p&gt; &lt;p&gt;Start with: “Find Donchian breakout strategies and list the available versions, entry and exit lookbacks, confirmation timing and Live Demo support. Compare their rules with this article before starting any trading.”&lt;/p&gt;  

</description>
      <category>algorithmictrading</category>
      <category>tradingbot</category>
    </item>
    <item>
      <title>Stop Market vs Stop Limit: Why a Triggered Stop May Not Fill</title>
      <dc:creator>AlgoRover</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:36:27 +0000</pubDate>
      <link>https://dev.to/algorover/stop-market-vs-stop-limit-why-a-triggered-stop-may-not-fill-47kg</link>
      <guid>https://dev.to/algorover/stop-market-vs-stop-limit-why-a-triggered-stop-may-not-fill-47kg</guid>
      <description>&lt;span&gt;Risk Management&lt;/span&gt; &lt;p&gt;A triggered stop is not a completed exit. Compare execution prices, working limits and remaining positions, then check what the backtest assumed.&lt;/p&gt;   &lt;p&gt;Your stop price was reached, yet the position is still open. Another stop sold successfully, but at a price noticeably below the number you entered. Both look like a stop failing to follow its settings, but they can be different problems.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;A stop-market order submits a market order after triggering and may fill at a worse price. A stop-limit order accepts only its limit price or better after triggering, so it may not fill at all.&lt;/strong&gt; The trigger starts the order process; it is not a promised execution price.&lt;/p&gt; &lt;h2&gt;Stop market vs stop limit: what does each control?&lt;/h2&gt; &lt;p&gt;Consider a sell stop protecting a spot holding. A stop-market order submits a market sell when its condition is met. A stop-limit order submits a limit sell. Triggering happens first; ordinary market or limit execution comes next.&lt;/p&gt; &lt;div class="table-wrapper-paragraph"&gt;What changes between the two sell stops&lt;table&gt;&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;Decision&lt;/th&gt;
&lt;th&gt;Stop market&lt;/th&gt;
&lt;th&gt;Stop limit&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Inputs&lt;/td&gt;
&lt;td&gt;Trigger price, quantity and trigger reference&lt;/td&gt;
&lt;td&gt;Trigger price, sell limit, quantity and trigger reference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After triggering&lt;/td&gt;
&lt;td&gt;Submit a market sell against available bids&lt;/td&gt;
&lt;td&gt;Submit a limit sell; accept the limit price or higher&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;During a fast drop&lt;/td&gt;
&lt;td&gt;Execution may occur at lower prices&lt;/td&gt;
&lt;td&gt;Bids below the limit cannot fill the order&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full execution&lt;/td&gt;
&lt;td&gt;Still depends on liquidity, protection limits and venue rules&lt;/td&gt;
&lt;td&gt;Also depends on eligible depth, queue priority and time in force&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt; &lt;p&gt;&lt;span&gt;Bybit's order documentation&lt;/span&gt; separates the conditional trigger from subsequent execution. Names, trigger choices and protection rules vary by venue and market, so check the order you are actually using.&lt;/p&gt; &lt;h2&gt;Stop-loss trigger price vs execution price: one order, two outcomes&lt;/h2&gt; &lt;p&gt;Suppose you bought 1 BTC at 50,000 USDT and want to sell on a decline to 48,000. Both stops use a trigger of 48,000. The stop-limit version also sets a minimum sell price of 47,900.&lt;/p&gt; &lt;p&gt;After triggering, suppose the available bids are 0.4 BTC at 47,850 and 0.6 BTC at 47,800, with no bids at 47,900 or higher.&lt;/p&gt; &lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stop market:&lt;/strong&gt; if those bids remain available and no additional protection restricts execution, the order can sell into both levels. The average fill price is 47,820.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop limit:&lt;/strong&gt; both bids are below the minimum of 47,900, so neither can fill it at that moment. A GTC order may remain working; an IOC order cancels its unfilled part under its time-in-force rules.&lt;/li&gt;
&lt;/ul&gt; &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstorage.ghost.io%2Fc%2F6d%2Fbb%2F6dbbb7cc-1f93-4cd3-8d75-e3c2cfce055f%2Fcontent%2Fimages%2F2026%2F11%2Fstop-execution-en-1.png" alt="For the same assumed bids, a one-BTC stop-market sell fills at 47850 and 47800 with an average of 47820; a sell limit of 47900 is above every available bid and cannot fill." width="800" height="750"&gt;An assumed 1 BTC sell. Both orders face the same book: 48,000 is the trigger, 47,900 the sell limit, and 47,820 the market order's weighted average fill. &lt;p&gt;&lt;span&gt;Kraken's stop-loss-limit guide&lt;/span&gt; also distinguishes the two prices and explains the possibility of non-execution during a fast decline. A sell limit of 47,900 prevents accepting lower fills; it does not cap the loss on a position that remains open.&lt;/p&gt; &lt;p&gt;If price keeps falling to 47,400 without eligible bids, the limit order may still be unfilled. You still hold the BTC and remain exposed to subsequent moves.&lt;/p&gt; &lt;h2&gt;How much does stop-loss slippage add?&lt;/h2&gt; &lt;p&gt;Before fees, selling at 48,000 would lose 2,000 USDT. Selling at the assumed average of 47,820 loses 2,180. The additional 180 USDT is 0.375% of the trigger price.&lt;/p&gt; &lt;p&gt;The average is quantity-weighted: 0.4 × 47,850 plus 0.6 × 47,800, divided by 1 BTC, gives 47,820. The 180 USDT belongs to this assumed book; it is not a fixed cost of every stop.&lt;/p&gt; &lt;p&gt;Add actual fees separately. An actual fill price already reflects its execution deviation. Subtracting the same estimated slippage again would double-count that cost.&lt;/p&gt; &lt;h2&gt;Why was my stop loss not triggered when the chart reached it?&lt;/h2&gt; &lt;p&gt;Check whether the chart and the order are watching the same price. Derivatives venues can distinguish last traded price, mark price and index price. The available references depend on the venue and market.&lt;/p&gt; &lt;p&gt;Suppose a sell stop triggers when the mark reaches 48,000. The last trade prints 47,950 while the mark remains at 48,020. A last-price chart appears to cross the stop, but the configured trigger condition has not been met.&lt;/p&gt; &lt;p&gt;This is why &lt;strong&gt;mark price vs last price&lt;/strong&gt; matters: the selected reference determines activation, while executable bids determine how a sell order fills. Triggering from the mark does not guarantee execution at the mark.&lt;/p&gt; &lt;p&gt;Also distinguish a program monitoring prices locally before submitting a sell from a conditional order already resting at the exchange. The former depends on the runtime and its data connection; for the latter, verify that the conditional order actually exists at the venue. A line drawn on a chart is insufficient evidence.&lt;/p&gt; &lt;h2&gt;Triggered but not filled: follow the order's actual state&lt;/h2&gt; &lt;p&gt;Use the same order identifier to connect the records, then investigate the stage it reached.&lt;/p&gt; &lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Not triggered:&lt;/strong&gt; check the reference price, trigger direction, condition and whether the stop remains active.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Triggered, then rejected:&lt;/strong&gt; read the rejection reason. Check balance or margin, minimum size, price restrictions and whether derivatives reduce-only instructions match the current position.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Working limit:&lt;/strong&gt; check the limit, eligible bids, queue and time in force. A last trade at your limit does not establish that your order filled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partially filled:&lt;/strong&gt; separate completed quantity, remaining order quantity and the remaining position.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local and exchange states disagree:&lt;/strong&gt; reconcile venue orders, fills and positions before submitting another sell.&lt;/li&gt;
&lt;/ol&gt; &lt;p&gt;For the quantity side, see &lt;span&gt;how to check positions and stop quantities after partial fills&lt;/span&gt;. If you close a position another way, also check whether an old protective order remains active, especially in derivatives.&lt;/p&gt; &lt;h2&gt;Which stop order fits the constraint you actually want?&lt;/h2&gt; &lt;p&gt;If the priority is to attempt an exit promptly after the condition, while accepting price deviation, stop market is closer to that objective. If you refuse to sell below a specific price and accept remaining invested, stop limit expresses that constraint.&lt;/p&gt; &lt;p&gt;Decide before placing the order. Widening the limit allows more bids to qualify but does not guarantee execution. There is no universally safe gap between the stop and limit prices for every asset and order size. Larger quantities need more eligible depth.&lt;/p&gt; &lt;p&gt;Market-order protection matters too: some venues restrict the acceptable execution range, leaving quantities beyond that range unexecuted. “Market” does not guarantee immediate liquidation of the entire holding under every condition.&lt;/p&gt; &lt;h2&gt;How to account for stop execution losses in a backtest&lt;/h2&gt; &lt;p&gt;A backtest that always sells the full position exactly at the stop can miss price gaps and insufficient depth. A stop-market model needs to consider worse execution. A stop-limit model also needs unfilled and partially filled paths, including the position held afterward.&lt;/p&gt; &lt;p&gt;A candle low of 47,400 does not prove that a stop triggered at 48,000 could sell at a limit of 47,900. It does not reveal queue priority, bid depth or order arrival time. Non-execution changes the later position, so subtracting a percentage from the original exit profit does not reproduce stop-limit behavior.&lt;/p&gt; &lt;p&gt;Compare ordinary execution, a gap through the limit and partial execution, then inspect how the strategy handles the remaining position. Our &lt;span&gt;analysis of slippage and backtest profits&lt;/span&gt; covers overall cost; the extra question here is whether this stop completed the exit at all.&lt;/p&gt; &lt;h2&gt;Frequently asked questions&lt;/h2&gt; &lt;h3&gt;Can the stop and limit prices be identical?&lt;/h3&gt; &lt;p&gt;If the venue permits it, yes. Available bids may already be below that price during a rapid decline, so the sell can remain unfilled. Matching the prices does not turn a limit order into a market order.&lt;/p&gt; &lt;h3&gt;Does a stop-limit order always pay maker fees?&lt;/h3&gt; &lt;p&gt;No. A triggered limit that immediately trades against resting bids may pay taker fees. Resting and later filling may qualify as maker execution. Check actual fills and the venue's fee rules.&lt;/p&gt; &lt;h3&gt;Does a stop-market order guarantee my maximum loss?&lt;/h3&gt; &lt;p&gt;No. The trigger does not fix the fill price. Gaps, depth and execution protection can change the outcome, and position size matters too.&lt;/p&gt; &lt;h3&gt;Should I submit another sell immediately after the stop triggers?&lt;/h3&gt; &lt;p&gt;First inspect completed fills, the remaining order and the current position. A second order can oversell. If replacing the first order, confirm its final cancellation state as well.&lt;/p&gt;  &lt;h2&gt;Use AlgoRover Live to follow the stop through its fills&lt;/h2&gt; &lt;p&gt;If you run strategies with &lt;span&gt;AlgoRover Live&lt;/span&gt;, inspect this stop's orders, fills and position together: which reference activated it, which order followed, how much sold and what remains. Review the process in a supported exchange Demo environment before deciding whether to change the execution rules.&lt;/p&gt; &lt;p&gt;Next time a stop appears to fail, bring the order identifier and its records. Finding where the process stopped is more useful than immediately replacing it with a more distant price.&lt;/p&gt;  

</description>
      <category>algorithmictrading</category>
      <category>tradingbot</category>
    </item>
  </channel>
</rss>
