Specialist degree, Moscow State University of Geodesy and Cartography, Russia, Moscow
PERFORMANCE ANALYSIS OF RUBY FRAMEWORKS IN THE CONTEXT OF SCALABLE WEB APPLICATION DEVELOPMENT
ABSTRACT
This study examines the architectural features of Ruby on Rails, Sinatra, and Hanami in the context of scalable web application development. It analyzes their approaches to HTTP request processing, database interaction, multithreading, asynchronous execution, and caching mechanisms, as well as the impact of these factors on overall performance. The study explores how the architectural decisions of these frameworks influence their ability to handle high loads and scale efficiently. Particular attention is given to differences in resource consumption, flexibility, and ease of integration with external services. Additionally, the performance of Ruby frameworks is evaluated based on existing benchmarks and comparative measurements.
АННОТАЦИЯ
В данной статье рассматриваются архитектурные особенности Ruby on Rails, Sinatra и Hanami в контексте разработки масштабируемых веб-приложений. Анализируются их подходы к обработке HTTP-запросов, работе с базами данных, поддержке многопоточности и асинхронности, а также механизмы кэширования и их влияние на производительность. Изучается влияние архитектурных решений этих фреймворков на их способность обрабатывать высокие нагрузки и эффективно масштабироваться. Особое внимание уделяется различиям в ресурсоемкости, гибкости и удобстве интеграции с внешними сервисами. Исследуется производительность Ruby-фреймворков на основе существующих тестов и сравнительных измерений.
Keywords: Ruby on Rails, Sinatra, Hanami, web frameworks, performance, scalability, HTTP request processing, multithreading, asynchronous processing.
Ключевые слова: Ruby on Rails, Sinatra, Hanami, веб-фреймворки, производительность, масштабируемость, обработка HTTP-запросов, многопоточность, асинхронность.
Introduction
The web application construction process requires the utilization of an implementation framework with strong load-resistance capability without compromising system stability. Ruby on Rails, Sinatra, and Hanami are the most utilized frameworks employed to build web applications with Ruby. The three frameworks vary in terms of architectural style, which determines their performance, database utilization, and scalability. With increased user bases sizes and data quantities, there is a need to assess which framework best suits deployment under high loads.
Comparing Ruby on Rails, Sinatra, and Hanami provides an understanding of their applicability to different development situations. Rails provides a strong yet monolithic framework with an integrated ecosystem, Sinatra focuses on simplicity and versatility, and Hanami tries to find a balance between modularity and performance. However, the actual impact of their architectural choices on request processing speed, resource consumption, and resilience under load remains a critical consideration. The goal of this research is to examine the differences in the performance of Ruby on Rails, Sinatra, and Hanami under high-load conditions.
Methods
Architectural features of Ruby on Rails, Sinatra, and Hanami in high-load environments
The choice of a framework for high-scaling Ruby application development is mostly determined by its architecture design. The main differences among Ruby on Rails, Sinatra, and Hanami are concerned with how each approaches HTTP request handling, database connection, caching, and handling asynchronous operations. All of these have a direct impact on the performance of the application, particularly under high loads.
Request handling is a fundamental aspect of any web framework. Ruby on Rails follows the Model-View-Controller (MVC) pattern and processes requests through a central controller that determines the necessary actions. While this type of style is ideal for producing intricate applications, it incurs overhead per request, primarily when multiple layers of middleware and intricate routing regimes are in play.
Sinatra, by contrast, is a minimalist library that integrates routing into the application code. Each route in Sinatra is defined as a standalone function, reducing overhead and improving request processing speed. By forgoing a complex structure and automatic loading of numerous components, Sinatra achieves high performance, particularly in small to medium-sized web applications.
Hanami occupies an intermediate position between Rails and Sinatra, adopting a modular approach to request handling. Unlike Rails, Hanami allows for selective component loading, enabling more flexible dependency management. This modular architecture makes Hanami lighter and more responsive under high loads, as applications can function with only the necessary components, reducing unnecessary resource consumption.
The table 1 presents a comparison of how Rails, Sinatra, and Hanami implement a simple REST API endpoint (/users) that retrieves a list of users from a database.
Table 1.
Implementation of the same functionality across different Ruby frameworks [1-3]
|
Frame work |
Configuration |
Controller code |
Routing |
Database query |
|
Ruby on Rails |
Rails + ActiveRecord + PostgreSQL |
class UsersController < ApplicationController def index users = User.all render json: users end end |
Rails.application.routes.draw do resources :users, only: [:index] end |
User.all (ActiveRecord ORM) |
|
Sinatra |
Sinatra + Sequel + PostgreSQL |
require 'sinatra' require 'sequel' DB = Sequel.connect('postgres://localhost/mydb') get '/users' do users = DB[:users].all users.to_json end |
get '/users', to: 'users#index' |
DB[:users].all (Sequel ORM) |
|
Hanami |
Hanami + ROM + PostgreSQL |
module Web::Controllers::Users class Index include Web::Action def call(params) users = UserRepository.new.all self.body = users.to_json end end end |
get '/users', to: 'users#index' |
UserRepository.new.all (ROM ORM) |
These differences highlight the varying design philosophies and trade-offs among Ruby frameworks. While Rails is convention-over-configuration and feature-rich, Sinatra is a minimalistic and flexible solution for minimalist applications. Hanami is a balance between modularity and performance and a good option for scalable applications. With these differences, developers are able to select the most appropriate framework based on project requirements and architectural style.
Another distinction is thread management and asynchronous processing, where different Ruby frameworks adopt varying approaches to concurrency and request handling efficiency. Ruby wasn't designed with multithreading as a top priority, and thus it has performance drawbacks for web applications. Rails has historically employed a multiprocess model, in which the application server (like Puma or Unicorn) forks multiple worker processes, each of which handles requests concurrently. This approach efficiently utilizes multi-core processors but leads to increased memory consumption. Recent versions of Rails have introduced improved support for multithreading through enhancements in ActiveSupport and concurrent-ruby [4]. However, interactions with databases and external services remain predominantly blocking, which can still impact overall performance.
Sinatra is a lighter framework that offers greater flexibility in the use of both multithreaded and multiprocess servers such as Puma and Thin. However, since it does not have built-in support for handling asynchronous tasks, developers prefer to use third-party libraries such as Sidekiq or Async in order to gain background processing and concurrency management.
Hanami, due to its architectural design, is optimized for more efficient resource utilization. It supports asynchronous request processing through compatibility with Fiber and event-driven paradigms, making it a strong candidate for high-load systems. With proper configuration, Hanami can achieve low latency and scale more effectively in environments with a large number of concurrent connections.
Database interaction and the impact of ORM on performance
Database efficiency of interaction is one of the factors that most influence the performance of web applications. Rails uses ActiveRecord, which provides a handy but occasionally too abstracted method of dealing with databases. ActiveRecord automatically creates SQL queries, which can lead to inefficient use of indexes, N+1 query issues, and increased latency in data processing.
Sinatra, lacking a built-in ORM, offers developers the flexibility to choose their preferred database management tools. The most commonly used options in Sinatra are Sequel or raw SQL queries executed via libraries such as PG. Sequel provides a more efficient and flexible approach compared to ActiveRecord, as it allows developers to have precise control over SQL queries, minimizing overhead associated with query generation.
Hanami employs ROM (Ruby Object Mapper), which represents an alternative approach to database interaction. Unlike ActiveRecord, ROM does not directly map objects to database tables but instead offers more flexible query-building mechanisms [5]. This design reduces overhead and enhances performance by giving developers finer control over SQL query execution. Additionally, Hanami supports lazy loading, which helps optimize response times when handling complex queries.
Caching mechanisms and their impact on scalability
Caching can have a dramatic effect on web application performance, particularly in load conditions. Rails provides in-built caching facilities through page caching, fragment caching, and query caching. ActiveSupport::Cache can be utilized with Redis or Memcached to reduce database loading substantially. Caching in Rails can, if misconfigured, boost overhead and conflict with system efficiency.
As a lightweight framework, Sinatra does not include a built-in caching system but allows seamless integration with external solutions such as Rack: Cache or Fastly. This approach offers developers greater flexibility, though it requires additional configuration and management to fully optimize caching performance.
Hanami provides built-in support for view-level and database caching, allowing for more efficient data management, which is particularly beneficial in high-load environments. Its architecture helps prevent unnecessary data retrieval, optimizing resource utilization. Furthermore, Hanami offers a better framework for the management of the state, thus enabling exact control over caching on the component level.
The variances that are seen in the architectural structures of Ruby on Rails, Sinatra, and Hanami significantly affect their scalability performance capabilities. Rails offers a strong but resource-hungry environment that is best suited to large-scale applications with complex functionalities. On the other hand, the lightweight framework of Sinatra supports efficient handling of requests but requires extra customization to maximize its scaling effectiveness. Hanami strikes an optimal balance between modularity and flexibility, thus supporting the efficient use of resources and the realization of high performance. The framework selection for systems that are prone to heavy loads will be dependent on the specific project needs, the nature of the workload, and the desired scalability.
Results
Performance analysis of Ruby frameworks in a scalable environment
The performance of web frameworks plays a crucial role in the development of scalable applications. Different approaches to request processing, database interaction, and caching mechanisms can significantly impact system speed and efficiency under high-load conditions.
The performance and evolution of Ruby frameworks remain a topic of discussion within the professional community. Ruby on Rails and Hanami, for instance, not only differ in how they handle requests and database interactions but also in their long-term maintenance and development activity. One way to assess the viability of a framework is to analyze its update frequency and community engagement. According to a study utilizing the Exponential Moving Average (EMA) method [6], Ruby on Rails exhibits significantly higher numbers of commits, contributors, and community interest compared to Hanami. This may indicate a more actively evolving ecosystem, a factor worth considering when selecting a framework for long-term projects.
Existing benchmark statistics indicate that Sinatra and Hanami process a higher number of requests per second (RPS) compared to Rails, as their architectures minimize overhead [7]. However, despite its lower RPS, Rails excels in handling large-scale applications, where built-in caching mechanisms and complex routing play a crucial role. Hanami, in turn, demonstrates stable performance and even surpasses Sinatra under high-load conditions, further validating its efficiency in scalability scenarios (fig. 1).
/Topalidi.files/image001.png)
Figure 1. Performance comparison of Ruby web frameworks based on RPS
The scalability of web frameworks depends on their ability to efficiently distribute load across processes and servers. Rails traditionally employs a multiprocess model, enabling applications to handle multiple requests concurrently but requiring significant computational resources. Sinatra, due to its lightweight nature, can be deployed across a large number of processes with lower memory consumption. Hanami, designed with a modular architecture, allows for selective loading of components, thereby reducing system overhead.
Horizontal scaling (adding more servers) in Rails introduces additional overhead, particularly when dealing with database-intensive operations. In contrast, Sinatra offers greater flexibility, as each application operates as an independent, easily scalable service. Hanami, with its component-based structure, enables efficient load distribution across multiple servers, making it a strong candidate for distributed systems.
A comparison of latency across different frameworks indicates that Rails exhibits the lowest P99 latency, showing its stability when handling large databases, primarily due to the built-in optimization mechanisms of ActiveRecord [8]. Hanami occupies an intermediate position, striking a balance between flexibility and performance. Sinatra, despite its high processing speed for simple requests, demonstrates higher latency under heavy load, which may be attributed to the lack of built-in optimization mechanisms and its dependence on server configuration (fig. 2).
/Topalidi.files/image002.png)
Figure 2. P99 latency analysis for Ruby on Rails, Sinatra, and Hanami under different load conditions, ms
A comparative analysis indicates that the choice of a framework depends on the specific requirements of a project. Sinatra is well-suited for high-load API and microservices, Rails remains a versatile tool for developing complex applications, while Hanami provides a balanced solution for flexible and scalable systems. These distinctions should be carefully considered in web application architecture design, particularly in scenarios involving increasing workloads and the need for scalability.
Conclusion
The efficacy and scalability of web frameworks form core elements in building modern-day applications, particularly in contexts with high demand. Among the most commonly used frameworks for Ruby include Sinatra, Ruby on Rails, and Hanami, each with different architectural approaches, HTTP request handling, database interactions, and features relevant to scalability. Sinatra shows greater effectiveness in handling simple requests with low resource usage, while Hanami has a highly structured module-based architecture; although with increased resource usage, it is a powerful tool for building intricate applications within a unified framework.
The choice between a suitable framework depends on a specific project's specific needs: Sinatra is most useful for building lightweight API and microservices, while Hanami provides a good balance between performance and flexibility. However, for big applications with complex business logic, Rails is still a good candidate. Understanding the differences between them in detail enables programmers to make informed decisions, considering both their functional characteristics and performance and scalability effects.
References:
- Zakharau A., Ponomarev E. The role of web applications in raising financial awareness and creditor debt management // ISJ Theoretical & Applied Science. – 2024. – № 139 (11). – S. 22-26. DOI: 10.15863/TAS.2024.11.139.6
- Using Rails for API-only Applications / Rails Guides [Electronic source] — Available at. — URL: https://guides.rubyonrails.org/api_app.html (Accessed on: 22.04.2025).
- Sinatra / Ruby Doc [Electronic source] — Available at. — URL: https://rubydoc.info/gems/sinatra (Accessed on: 24.04.2025).
- Ulanov A. Utilizing Real Time Technologies in Ruby Web Applications // Internafional Journal of Computer Science and Mobile Compufing. – 2022. – № 11 (12). – S. 34-45. DOI: 10.47760/ijcsmc.2022.v11i12.002
- Pantelelis M., Kalloniatis C. Mapping CRUD to Events-Towards an object to event-sourcing framework // InProceedings of the 26th Pan-Hellenic Conference on Informatics. – 2022. – S. 285-289. DOI: 10.1145/3575879.3576006
- Júnior R.R., de Souza H.A. Mining repositories to analyze the lifecycle of frameworks and libraries // InSimpósio Brasileiro de Engenharia de Software (SBES). – 2024. – S. 602-608).
- Benchmark Result: Request / Web Frameworks Benchmark [Electronic source] — Available at. — URL: https://web-frameworks-benchmark.netlify.app/result?asc=0&l=ruby&metric=totalRequestsPerS&order_by=level64 (Accessed on: 01.05.2025).
- Benchmark Result: P99 Latency / Web Frameworks Benchmark Electronic source] — Available at. — URL: https://web-frameworks-benchmark.netlify.app/result?asc=1&l=ruby&metric=percentile99&order_by=level64 (Accessed on: 04.05.2025).