Skip to content

Instantly share code, notes, and snippets.

@rponte
Last active August 30, 2025 21:31
Show Gist options
  • Save rponte/a69b9cf237a81857bfceff6a5b18c09b to your computer and use it in GitHub Desktop.
Save rponte/a69b9cf237a81857bfceff6a5b18c09b to your computer and use it in GitHub Desktop.
Content about implementing a database-based queue with SQL, SKIP LOCKED and LISTEN/NOTIFY
@rponte
Copy link
Author

rponte commented Nov 6, 2024

Thread no Twitter do criador da Crunchy Data, Craig Kerstiens, com dicas sobre como desenhar uma boa solução de fila de mensagens no Postgres.

De acordo com o Craig, não é algo muito dificil, basta seguir estas 3 regras:

  1. Try to have index-only scans and very low BUFFERS numbers in the execution plans (not degrading over time;
  2. Most important (derived from "1", actually): take into consideration the Postgres MVCC model. Don't use DELETE for cleanup. Remember that any UPDATE is physically DELETE+INSERT. Design for low bloat. Most likely, decisions will involve partitioning and/or TRUNCATE;
  3. Consider using SKIP LOCKED to have multiple consumers. In most cases, this is overrated, though, being a premature optimization for throughput – if you have low latency (SQL is written well), a single consumer might be enough;

Ele também cita mais algumas dicas após eu questioná-lo sobre práticas de design para evitar BLOAT no Postgres.

@rponte
Copy link
Author

rponte commented Nov 21, 2024

This very good article explains how to build a sophisticated and highly-scalable platform (social network) using Postgres LISTEN/NOTIFY and SKIP LOCKED:
Listening to Postgres: How LISTEN and NOTIFY Syntax Promote High Availability at the Application Layer

@rponte
Copy link
Author

rponte commented Nov 22, 2024

@rponte
Copy link
Author

rponte commented Nov 22, 2024

Mastering SKIP LOCKED in MySQL

Over the past few months, I've been deeply involved in designing a system that pushes MySQL's SKIP LOCKED feature to its limits. This journey revealed several nuances and optimization opportunities that can significantly impact performance. In this post, we'll explore these insights, demonstrating how to reduce lock overhead, optimize schema design, and fine-tune transaction isolation levels to achieve remarkable performance gains.

@rponte
Copy link
Author

rponte commented Mar 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment