From Local to Global: Making Rails apps resilient

me Guillaume Briday

Lyon.rb - September 30, 2025

A little bit of context

Kamal: Why and how you should leave the cloud?
// Paris.rb at @algolia
Web performance myths busted
// Paris.rb at @LeWagon
guillaumebriday.fr/articles

The plan for today

  1. Before starting
  2. What makes an app resilient?
  3. How and why to deploy your app globally?
  4. It's not a silver bullet
me
Lead dev at Open source contributor

✌️ @guillaumebriday 👉 https://guillaumebriday.fr

Before starting

Let's start with a few reminders

Scalability and resilience

They are two sides of the same coin

  1. Scalability: The ability to handle increasing load
  2. Resilience: The ability to recover and continue operating despite unexpected conditions

Different types of scaling

Different types of scaling

Complexity Resilience
Vertical 😎 🥵
Horizontal 🥵 😎

Not all solutions are created equal

Stateless vs Stateful

  • Scaling multiple stateless services is easy
  • Scaling a single stateful service is really hard

Rails is not slow, your database is

Web performance is mostly about latency

Most web apps spend most of their life waiting

Web performance is mostly about latency

  • TCP/TLS/DNS/HTTP
  • Network
  • Concurrency (threads)
  • Database queries (n+1, round-trip, pooling)
  • API calls
  • Serialization
  • Multi-AZ
  • External storages (S3, EBS, SSD, Blocks, etc)
  • Client-side processing (SPA)

Web performance is only about latency

The more (micro)-services you have, the more latency you have

What makes an app resilient?

I spent 2 years living in NYC...

The latency was terrible...

(Geo)-Load balancer, performance and resilience

An entirely different dimension of complexity

Replication and horizontal scaling is the only way

Vertical scaling

Simple Horizontal scaling

Not so simple Horizontal scaling

Global load balancer

  1. Really hard to implement
  2. Only few providers (AWS, Fly.io, GCP, Cloudflare, etc)
  3. Could be simplified with subdomains (eu., us.)
  4. 95% of requests are GET/Read

A single point of failure

DB replication

DB replication

  • pg_basebackup
  • One Primary / Multiple Replica
  • Manual or Auto failover
  • Replays Write-Ahead Log (WAL)
  • Real-time streaming replication

Rails 6.0: multi-db

Rails multi-db

config/database.yml
            
production:
  primary:
    url: <%= ENV['DATABASE_PRIMARY_URL'] %>
    adapter: postgresql

  primary_replica:
    url: <%= ENV['DATABASE_REPLICA_URL'] %>
    adapter: postgresql
    replica: true
            
          
app/models/application_record.rb
            
class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true

  connects_to database: { writing: :primary, reading: :primary_replica }
end
            
          

Global and resilient

Conclusion

  • Deploy apps globally is really complex
  • Optimize before going too far
  • Probably overkill most of the time
  • Replication is needed for resilience anyway
  • Hidden complexity (monitoring, credentials, costs, ROI, pooling management)
  • Best (only?) option for upgrades and migrations

Thanks! 🙏

https://guillaumebriday.fr/talks