Faster Rails: Indexing Large Database Tables Without Downtime
Blog post from Semaphore
As Rails projects grow in scope and size, previously fast actions can become slow due to the exponential growth of database tables, making lookups and updates sluggish. A simple solution to improve performance is adding missing indexes, but this poses risks, especially in live production databases where creating indexes synchronously can lock tables and cause downtime. PostgreSQL offers a concurrent index creation option, allowing index building without locking tables, although it increases CPU and I/O load and takes longer to complete. In Rails, the algorithm option in migrations can trigger concurrent index builds, but this requires disabling the default transaction wrapper using disable_ddl_transaction! to avoid locking. Implementing this method at Semaphore significantly improved job processing speed by 2.5 times. While premature optimization can be counterproductive, understanding system metrics and making informed tweaks can yield substantial performance gains. Semaphore is focused on enhancing continuous integration speed, recently introducing a feature that parallelizes test suites to reduce runtime.