API throttling with custom Redis-based limiter

While Rack::Attack handles basic rate limiting, custom throttling logic gives fine-grained control over quotas, burst allowances, and per-feature limits. I implement a token bucket algorithm in Redis using sorted sets to track request timestamps per u

Action Cable for real-time WebSocket communication

Action Cable brings WebSocket support to Rails, enabling real-time features like live notifications, collaborative editing, or chat systems. Clients subscribe to channels that broadcast updates when server-side events occur. I use Redis as the pub/sub

Custom middleware for request tracking

Rack middleware sits between the web server and Rails application, providing a hook for cross-cutting concerns like request logging, metrics collection, or custom authentication. I use middleware to inject request IDs, track response times, or enforce

GraphQL API with graphql-ruby gem

GraphQL provides clients flexibility to request exactly the data they need, reducing over-fetching and under-fetching compared to REST. The graphql-ruby gem integrates GraphQL into Rails with a schema-first approach. I define types for each model, fie

Database read replicas for scaling reads

As applications grow, read operations often dominate database load. Directing reads to replica databases while keeping writes on the primary reduces contention and improves response times. Rails makes this straightforward with connects_to and role-bas

Environment-specific configuration with Rails credentials

Storing secrets in environment variables works but gets messy at scale with dozens of keys. Rails encrypted credentials provide a structured alternative where secrets live in version-controlled credentials.yml.enc files, encrypted with a master key st

Soft deletes with paranoia gem

Hard deletes make data recovery impossible and complicate audit trails. Soft deletes mark records as deleted without removing them from the database, preserving history and enabling undo functionality. The paranoia gem adds a deleted_at timestamp colu

API documentation with Swagger/OpenAPI

Auto-generated API documentation from code annotations keeps docs in sync with implementation and reduces maintenance burden. The rswag gem generates OpenAPI 3.0 specs from RSpec request specs, providing interactive documentation via Swagger UI. I wri

Redis caching for expensive computations

Redis provides a fast, in-memory cache for expensive computations that don't change frequently. I use Rails.cache with the Redis store to cache things like trending posts calculations, aggregated statistics, or external API responses. The fetch method

Database constraints for data integrity

While ActiveRecord validations catch most invalid data, database constraints provide a safety net that prevents invariant violations even when validations are bypassed. I add null: false constraints for required columns, unique indexes for uniqueness

Polymorphic associations for flexible relationships

Polymorphic associations allow a model to belong to multiple other models through a single association, which is useful for shared behaviors like comments, likes, or attachments. Instead of separate post_id and article_id columns, a polymorphic associ

Background job retry strategies

Not all background job failures should be retried the same way. Transient failures like network timeouts benefit from exponential backoff, but bugs in code or invalid data should fail immediately after a few attempts. Sidekiq provides retry configurat