database

Room database for local persistence

Room provides an abstraction layer over SQLite for compile-time verified database access. I define entities with @Entity annotation, specifying table structure and relationships. DAOs (Data Access Objects) marked with @Dao contain query methods using

Database replication and high availability strategies

Replication copies data across multiple servers for redundancy and scalability. Master-slave replication has one writable primary, multiple read-only replicas. I use read replicas to scale read-heavy workloads. Master-master allows writes to multiple

Optimistic locking for concurrent updates

When multiple users can update the same record simultaneously, optimistic locking prevents lost updates by detecting conflicts. Rails provides built-in support via a lock_version integer column that increments on every update. If two users load the sa

Database schema migrations and versioning

Schema migrations evolve database structure safely. I use migration tools like Flyway, Liquibase, or framework migrations. Version-controlled migrations track schema changes. Up migrations apply changes, down migrations revert. Idempotent migrations c

Database connection pooling configuration

Properly configured connection pools prevent ActiveRecord::ConnectionTimeoutError during traffic spikes while avoiding resource waste. The pool size should match your application's concurrency needs—for Puma with 5 threads per worker, I set pool: 5 in

JSON column for flexible schema extensions

PostgreSQL's jsonb columns provide schema flexibility for semi-structured data without sacrificing query performance. I use JSON columns for user preferences, feature flags, or metadata that varies by record type. Unlike traditional EAV patterns, json