My previous article about timezones turned out to be useful for quite a few folks, which makes me happy. One candle lights another. Ben Sheldon asked about then actually doing something with those converted times. How do you actually send a newsletter every morning on every working day, regardless of what the user’s time zone is? There are a number of approaches to this - once you know the UTC time of the delivery. I will cover a few of them, including the one I prefer. Let’s wind the clocks!
Easy to Overlook PostgreSQL Performance Issues in Rails Apps
Performance issues in the PostgreSQL layer usually start to manifest only when your app reaches a certain scale. In this blog post, I'll discuss easy-to-miss database config tweaks and common problems that I've encountered in multiple Rails projects.
Using LLMs and MCP to Debug PG Performance in Rails
I've recently automated a large portion of my Rails performance audits. In this tutorial, I'll describe how to configure an AI-powered PG performance debugging. We will cover using LLMs with custom MCP (model context protocol) n8n integration. We will also discuss the legal and security implications of connecting AI to the production database. There’s also a live demo available!
Big Problems From Big IN lists with Ruby on Rails and PostgreSQL
Personal Site Andrew Atkinson. PostgreSQL. Ruby on Rails, Elasticsearch, Kubernetes, Vim. Author High Performance PostgreSQL for Rails Pragmatic Programmers
A Practical Guide to Postgres Isolation Anomalies and How To Tame Them
Postgres is a powerful and versatile database management system, now ubiquitously used in all types of applications. In the context of web services, its most important property is the ability to serve multitudes of users at the same time. This article explores how Postgres makes it possible by examining what can go wrong when transactions from multiple users interweave - it covers isolation levels and possible anomalies, along with ways to avoid them
I just recently stumbled upon a feature of postgres I didn’t know about yet, its called pg_inheritance. It is basically the possibility of creating child tables which inherit the columns of the base table, although other things such as constraints. The main use case for this is table partitioning, but as I read the docs I was thinking it could might be useful for Model inheritance in rails as well.
Using CTID Based Pagination for Data Cleanups in PostgreSQL
When dealing with very large PostgreSQL tables (we're talking 15TB+), sometimes routine maintenance like archiving very old data can become surprisingly challenging
Speed Up Compound Full-Text Searches in PostgreSQL by 300x - RorVsWild
Querying your database across associations can become a bottleneck in your Rails application. Julian Rubisch, our first guest author, explains why and suggests an efficient solution.
Scaling Rails & Postgres to Millions of Users at Microsoft: Lessons & Takeaways – StepChange
Do you have a Rails app built on PostgreSQL and need to scale it to millions of users? In this interview, I speak with Andrew Atkinson, one of StepChange's expert consultants, who brings deep expertise in optimizing Rails applications for performance and scalability. Andrew’s expertise is backed by real-world experience—during his tenure at Microsoft, he played a key role in scaling the infrastructure for Flip (formerly Flipgrid), a video discussion and sharing app built for classrooms and beyo
How to Add PostgreSQL Index based on Query Plan as a Rails Developer | Haseeb Annadamban
As Rails developers, we often focus on writing clean, efficient Ruby code. However, as the application grows optimizing database performance is equally crucial for creating responsive applications. One of the most powerful tools in our arsenal for database optimization is indexing. Here I will talk about PostgreSQL indexing from a Rails developer’s perspective. The query plan generated by EXPLAIN will help us to make informed decisions about index creation, ensuring our database queries run as efficiently as possible.
Video of a conference talk about Saas on Rails on PostgreSQL presented by Andrew Atkinson at POSETTE: An Event for Postgres 2024. In this talk attendees will learn how Ruby on Rails and PostgreSQL can be used to create scalable SaaS applications, focusing on schema and query design, and leveraging database capabilities. We’ll define SaaS concepts, B2B, B2C, and multi-tenancy. Although Rails doesn't natively support SaaS or multi-tenancy, solutions like Bullet Train and Jumpstart Rails can be used for common SaaS needs. Next we'll cover database designs from the Apartment and actsastenant gems which support multi-tenancy concepts, and connect their designs to Citus's row and schema sharding capabilities from version 12.0. We’ll also cover PostgreSQL's LIST partitioning and how to use it for efficient detachment of unneeded customer data. We'll cover the basics of leveraging Rails 6.1's Horizontal Sharding for database-per-tenant designs. Besides the benefits for each tool, limitations will be described so that attendees can make informed choices. Attendees will leave with a broad survey of building multi-tenant SaaS applications, having reviewed application level designs, database designs, to help them put these into action in their own applications.
Andrew is a Staff Software Engineer who specializes in building high performance web applications using PostgreSQL and Ruby on Rails.
Andrew wrote a book "High Performance PostgreSQL for Rails," published by Pragmatic Programmers in 2024. Andrew has spoken previously at RailsConf, Sin City Ruby, PGDay Chicago, PGConf NYC, and RubyConf Argentina.
Chapters:
00:00 - Intro
00:39 - Overview of the presentation
01:10 - Definition of terms
05:36 - Adding multi-tenancy to Rideshare application
12:55 - Scaling beyond a single PostgreSQL instance
14:27 - Multi-Tenancy and Sharding with Active Record
17:02 - Citus and Sharding
22:52 - Wrap Up and Advice
📕 Everything you need to know about POSETTE: An Event for Postgres 2024 can be found at: https://aka.ms/posette
✅ Learn more:
Watch more POSETTE talks: https://aka.ms/posette-playlist
📌 Let’s connect:
X – @PosetteConf https://x.com/PosetteConf
Mastodon - @posetteconf https://mastodon.social/@posetteconf
Threads – @posetteconf https://www.threads.net/@posetteconf
🔔 Subscribe to the POSETTE News: https://aka.ms/posette-subscribe
📣 Slides for this talk: https://speakerdeck.com/andyatkinson/saas-on-rails-on-postgresql
#PosetteConf #PostgreSQL #Ruby
Presenters:
Andrew Atkinson, Staff Software Engineer, Author
Connect:
Andrew Atkinson: https://mastodon.social/@andatki, https://twitter.com/andatki, https://www.linkedin.com/in/andyatkinson/
We are excited about some of the Active Record updates with Rails 7.1! Chris reviews some of the notable new features for working with Postgres including async queries, composite primary keys, native support for CTEs, unlogged tables, and syntax normalization.
High Performance PostgreSQL for Rails: Reliable, Scalable, Maintainable Database Applications by Andrew Atkinson
Build fast, scalable PostgreSQL and Rails apps. Solve data growth, quality, and reliability challenges, for workloads from consumer Internet to enterprise SaaS.
How we got struck by 5–year–old implementation | Arkency Blog
How we got struck by 5–year–old implementation Recently we discovered that we were wrong on computing lock key for acquiring advisory locks. It was already covered as an update to article about building read models, but we thought that telling the whole story behind the issue could be interesting for you.
Soft deletion with PostgreSQL: but with logic on the database! — Martian Chronicles, Evil Martians’ team blog
Rubyists might take special pleasure here, but every SQL and PostgreSQL dev can learn this unorthodox approach: putting soft delete logic on the database side.
How to fake time in a Postgres database: And an example Ruby on Rails app, too!
Mocking or freezing time when testing your application? Ruby and JavaScript make it easy … until your database is involved. Here's a way to time travel in Postgres!
fatkodima/online_migrations: Catch unsafe PostgreSQL (MySQL soon) migrations in development and run them easier (helpers for table/column renaming, changing column type, adding columns with default, background migrations, etc) in production.
Catch unsafe PostgreSQL migrations in development and run them easier in production (code helpers for table/column renaming, changing column type, adding columns with default, background migrations...