Postgres, Performance and Rails

Опубликовано: 16 Октябрь 2024
на канале: SaaS Developer Community
460
20

Andrew Atkinson took a Rails web application that was struggling with load, and optimized it to handle over 9000 HTTP requests per second with an average latency of 35ms end to end. Handling a much higher load, on a smaller RDS instance, with lower latencies. He then shared his expertise by writing a book: "High-Performance Postgres with Rails."

Andrew and I discussed Postgres performance, scalability, design patterns, valuable tools, his career, and some Rails. I tackled Andrew with many of the biggest challenges SaaS developers encounter with Postgres, and Andrew had an answer to everything.

For me, the highlights were his explanation of the N+1 problem, sharding patterns, the use of pgcopydb project to move a noisy neighbor to another DB, and the secret for scaling on a single instance.

Useful links:
The book: https://pgrailsbook.com
SaaS Developer Slack - where Andrew answers Postgres questions and will share a discount for his book: http://launchpass.com/all-about-saas
Andrew's playlist with all his content:    • "Partitioned Table Conversion: Concep...  

Tools we mentioned:
Easier multi-tenancy for Rails: https://github.com/ErwinM/acts_as_tenant
For read replicas for Rails prior to 6.0: https://github.com/OutOfOrder/multidb
The fastest way to copy a DB or part of: https://github.com/dimitri/pgcopydb

Chapters:
00:00 Intros
00:48 High-Performance Postgres for Rails
03:54 Meaning of High Performance
05:14 What came first, the Postgres or the rails?
06:46 How does a Rails developer become interested in DB performance?
10:42 Take a loaded DB and make it better
12:36 Dealing with a high rate of updates and deletes
13:20 Architecture and scalability decisions
14:36 Can you get good DB performance with Rails?
17:26 The N+1 problem
21:13 Why work with ActiveRecord?
25:00 Multi-tenant databases
29:57 Tools for horizontal and vertical sharding
33:24 Read-only replicas
39:46 Migrating one tenant to another DB
44:10 Extreme performance
47:27 The key to single instance performance
50:15 It was fast in staging
52:52 Solving DB performance in the app layer