Double Buffering with Cloudflare Queues

(bellone.com)

49 points | by b_llc 3 days ago ago

5 comments

  • b_llc 3 days ago

    A stateless pattern I use to batch telemetry at the edge while driving Cloudflare write costs to zero.

    • fwlr 8 hours ago

      Cool pattern. Critics will say ā€œfalsehoods programmers believe about timeā€ but it’s a cloud service, any time oddity that would break this would also break a lot more important stuff, so it’s fine.

      Ugly code though.

        // env
        QUEUES = [EVEN_QUEUE, ODD_QUEUE]
      
        // producers
        env.QUEUES[hour % 2].send …
      
        // consumer
        env.QUEUES[1 + hour % 2]
      • danhite 3 hours ago

        > env.QUEUES[1 + hour % 2]

        // results in index 1 or 2 as js has precedence for */% over +-

        So something like the following, for your desired visual succinctness? ...

        env.QUEUES[hour % 2 ^ 1]

        // results in desired js index 0 or 1

        I wonder if any of you using AI code assistance regularly might tell an old hack like me if your code review tools would have caught such a bug?

    • raffraffraff 5 hours ago

      Can you explain the pricing here?

      • b_llc 2 hours ago

        Cloudflare R2 bills on writes ($4.50/M), reads ($0.36/M), and storage ($0.015/GB/mo). The free tier gives you 1M writes, 10M reads, and 10GB per month. If you batch uploads hourly, you only make ~720 writes a month. That completely eliminates write costs, leaving storage as the only expense.