7 comments

  • atombender2 hours ago
    A performance pitfall that isn&#x27;t addressed in the DBOS article at all is the bloat problem: If you update or delete rows that you consume, dead tuples start to accumulate due to Postgres&#x27; way of doing MVCC.<p>This is a serious problem because it affects the planner&#x27;s ability to make good choices. Dead tuples are still indexed and the need to skip them isn&#x27;t accounted for by the query planner, so a table with lots of dead tuples may perform really badly. The autovacuum process will be constantly chasing dead tuples, and you&#x27;ll want to set the autovacuum settings to be very aggressive to be able to keep up.<p>My team has been starting to use PgQue [1] for a new application, and it seems really well-designed. PgQue is explicitly designed to solve the bloat problem, by avoiding tuple deletion. Instead of deleting processed tuples, it will periodically TRUNCATE the entire table. It uses two tables that it &quot;flips&quot; between so TRUNCATE can run on the inactive table while the active on is used for queuing. PgQue also uses a snapshot approach to avoid row-level locks.<p>PgQue also stands out in that its queue model is position-based, so it can implement nice features like collaborative consumers, fan-out, atomic batches, and &quot;recover from last good&quot; behaviour. It makes some compromises (no priority support, slightly higher latency), but they&#x27;re fine for most use cases.<p>Previously discussed on HN here [2].<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;NikolayS&#x2F;pgque" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;NikolayS&#x2F;pgque</a><p>[2] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47817349">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47817349</a>
    • KraftyOne50 minutes ago
      This is something we mention in the third section of the article: dead tuples and autovacuum caused real performance hits, which we (partially) mitigated through index optimization (minimizing the number and size of indexes, and making indexes partial).<p>PgQue is a really interesting system! However, its semantics are quite a bit more similar to Kafka than to a job queue, which is good for some workloads and not for others. For example a truncation-based deletion system is fast but inflexible, and not suitable for a job queue system because a single long-running job (and DBOS supports workflows that run for months) can block truncation.
    • sgt1 hour ago
      Not a problem unless your system has busy queue processing 24&#x2F;7 though, which I bet is pretty rare for most companies.
      • atombender39 minutes ago
        Not true, unfortunately. The dead tuple build-up can happen in a very short amount of time. I speak from having had to deal with this in a production environment that used the SKIP LOCKED method used in the article.
  • dewey4 hours ago
    &gt; The conventional wisdom around Postgres-backed queues is that they don&#x27;t scale.<p>That might have been the case 10 years ago. In the past years there have been many Postgres powered queueing systems and even Rails switched to Postgres powered queues by default (SolidQueue) more than 3 years ago.
    • mjfisher2 hours ago
      I see a lot of back and forth about postgres&#x27; suitability as a queuing system. I wonder if there&#x27;s a couple of separable problems here. Postgres backed queues - even very scalable ones - might work well for background jobs in a monolithic app backed by a single DB. Things like backgrounding sending an email etc.<p>But usually when I reach for a queuing system, it&#x27;s because I want to decouple a part of the architecture. And in that case, it&#x27;s probably better to use a dedicated queueing system instead of postgres.<p>I wonder if the two cases are conflated in a lot of online discussion.
      • dewey2 hours ago
        We are very heavily using Postgres as a queuing system in production for many years already, not just some quiet background tasks but with millions of tasks in the queue at any given moment. I have yet so see any issues with that so I&#x27;m always a bit suspicious when people say they had to reach for something else unless you are at a crazy scale.<p>I know it&#x27;s very hard to compare workloads, but famous recent example: <a href="https:&#x2F;&#x2F;openai.com&#x2F;index&#x2F;scaling-postgresql&#x2F;" rel="nofollow">https:&#x2F;&#x2F;openai.com&#x2F;index&#x2F;scaling-postgresql&#x2F;</a><p>&gt; It may sound surprising that a single-primary architecture can meet the demands of OpenAI’s scale; however, making this work in practice isn’t simple.
        • tomnipotent1 hour ago
          That post is about how Postgres doesn&#x27;t scale for write-heavy workloads and that they had to move those workloads to Cosmos DB. For the rest of the remaining mostly-read workload they have a single primary with 50 read replicas.
          • dewey1 hour ago
            The point is that Postgres scales a very long way. Once you arrive at OpenAI &#x2F; ChatGPT scale there&#x27;s no shame in reaching for a dedicated queuing system.
            • tomnipotent1 hour ago
              &gt; scales a very long way<p>This ignores the fine print. It scales a very long way under specific circumstances with specific workloads. The more write-heavy your workload the less eloquently Postgres scales.<p>For OpenAI&#x27;s use case you could swap Postgres with MySQL and it would scale just as well.
              • ballon_monkey1 hour ago
                If your DB is write heavy, tune it for writes...
                • tomnipotent1 hour ago
                  You can&#x27;t tune your way out of this constraint. The heap table and MVCC implementation put a hard ceiling on what can be accomplished without reaching for another tool.
    • bel82 hours ago
      I have the impression that SolidQueue uses whatever your rails app is using by default. That can be SQLite, PostgreSQL, MySQL, etc.<p>So I don&#x27;t think they changed to PostgreSQL per se.
      • dewey1 hour ago
        Correct, what I meant was that SolidQueue was the first database-backed default adapter over the usually common Redis + Sidekiq combo for ActiveJob.
  • rtpg24 minutes ago
    we had a whole discussion at work around whether to not to use pg for queues at a reasonable size (in particular for doing some notion of fair queueing distribution across tenants).<p>I ended up finding a good number of HN comments like &quot;we were doing this and regretting it&quot;.<p>So here&#x27;s my ask: anybody here use PG for queues at a system with reasonable throughput, without regretting it? Like where there might be some contention
  • rcleveng1 hour ago
    Are these posted manually or is there a scheduled claude co-work task that does it?
  • sorentwo3 hours ago
    They certainly do, and I don&#x27;t think it&#x27;s a controversial take at this point.<p>Shameless link to an older article about throughput with Oban (<a href="https:&#x2F;&#x2F;oban.pro&#x2F;articles&#x2F;one-million-jobs-a-minute-with-oban" rel="nofollow">https:&#x2F;&#x2F;oban.pro&#x2F;articles&#x2F;one-million-jobs-a-minute-with-oba...</a>), and in follow-up research we&#x27;ve sustained 12k&#x2F;s with a p99 under ~100ms.
  • richwater3 hours ago
    Reading Postgres queuing posts always seem like deja vu. People love to write about them
    • keeganpoppen2 hours ago
      everyone sure acts like postgres is some sort of thing that we discovered next to the antikythera mechanism on the sunken isle of atlantis. the &quot;just get one big machine to do all of the stuff&quot; scaling strategy remains undefeated, though. even if it is presented like it is anything but.
    • mlnj3 hours ago
      These days, most of them are from the DBOS folks. :)
      • tonyhb2 hours ago
        indeed, every ~week with essentially the same thing: skip locked.
  • everfrustrated2 hours ago
    [flagged]