
Performance Optimization
Database indexing, query optimization, Bullet gem, rack-mini-profiler, concurrency/Puma, thread-safety, connection pool
1What is the main purpose of adding an index on a database column?
What is the main purpose of adding an index on a database column?
Câu trả lời
An index speeds up search queries by creating an optimized data structure (usually a B-tree) that avoids scanning all rows in the table. Without an index, the database performs a sequential scan which can be very slow on large tables. Columns frequently used in WHERE clauses, ORDER BY or joins are ideal candidates for indexing.
2How to create a composite index on user_id and created_at columns in a Rails migration?
How to create a composite index on user_id and created_at columns in a Rails migration?
Câu trả lời
The add_index method accepts an array of columns to create a composite index. Column order matters: the index will be efficient for queries filtering first on user_id, then created_at, but not for queries filtering only on created_at. A composite index is optimal for queries using columns from left to right.
3What is the N+1 problem in the context of ActiveRecord?
What is the N+1 problem in the context of ActiveRecord?
Câu trả lời
The N+1 problem occurs when an initial query retrieves N records, then N additional queries are executed to load each record's associations. For example, loading 100 posts then making 100 individual queries for authors. This pattern multiplies the number of queries and severely degrades performance. The solution is to use includes, preload or eager_load to load associations in one or two queries.
Which ActiveRecord method to use to solve the N+1 problem by loading associations in advance?
What is the role of the Bullet gem in Rails performance optimization?
+23 câu hỏi phỏng vấn
Các chủ đề phỏng vấn Ruby on Rails khác
Ruby Basics
Ruby Object-Oriented Programming
Rails Fundamentals
Routing & Controllers
ActiveRecord Basics
Views & ERB Templates
ActiveRecord Associations
Advanced ActiveRecord Queries
Rails Forms
Authentication & Authorization
Modern Asset Pipeline & Frontend
Rails API Mode
Testing with RSpec
ActiveJob & Background Jobs
ActionCable & WebSockets
ActionMailer
ActiveStorage
Caching Strategies
Advanced Migrations
Rails Engines & Modular Apps
Rails Design Patterns
Ruby Metaprogramming
Rails Security
GraphQL with Rails
Deployment & Production
Monitoring & Logging
Rails Upgrade Strategies
Nắm vững Ruby on Rails cho lần phỏng vấn tiếp theo
Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.
Bắt đầu miễn phí