October 20, 2026
Structuring and best practices of RESTful APIs with Ruby on Rails
Structuring and Best Practices of Restful APIs with Ruby on Rails
Vitor Sant’Ana Navarro; Alexandre Leite Rangel
DOI: 10.22167/2675-6528-202602420
Article derived from a Course Conclusion Work (TCC), with content based on the student’s original work and adapted to the editorial format of the E&S Magazine with the support of the ResumeAI tool, an artificial intelligence solution developed by Instituto Pecege for textual synthesis and organization.
Summary
The development of RESTful APIs with adequate technical quality requires the adoption of structured practices that encompass security, performance, documentation, and maintainability, aspects often overlooked in initial implementations. This study analyzed the impact of the progressive adoption of best practices in the development of RESTful APIs with the Ruby on Rails framework. To this end, three experimental prototypes with increasing levels of technical maturity were implemented and comparatively evaluated in a controlled environment. Performance metrics were collected using Apache JMeter, and the perception of 25 IT professionals was assessed through questionnaires. The findings indicated that the progressive adoption of best practices introduced measurable costs in complexity and latency. JWT authentication, for example, increased the average response time by approximately 76% under peak load. Redis caching did not show performance gains in the local test environment due to low database latency, but its benefit is expected in production. All prototypes maintained a null error rate, demonstrating functional stability. Professionals considered the most advanced prototype (P3) the most prepared for growth (72%), while the intermediate one (P2) was pointed out as having the best cost-benefit ratio (64%). This demonstrated that the adoption of advanced practices is contextual and progressive, implying a trade-off between security/maturity and immediate feasibility, which supported an incremental development approach in real projects.
Keywords: RESTful APIs; JWT Authentication; Redis Cache; Ruby on Rails; Performance testing.
1. Introduction
The development of RESTful APIs has consolidated itself as a fundamental practice in the construction of modern systems. These distributed architectures demand scalability, security, and efficient integration between heterogeneous services, as highlighted by Fielding (2000) and Pautasso et al. (2008). The growing adoption of this architectural model imposes on development teams the need to structure implementations based on practices that guarantee not only functionality but also the reliability, maintainability, and security of the developed systems (Gowda and Gowda, 2024; Golmohammadi et al., 2023).
In this scenario, the Ruby on Rails framework stands out for offering high productivity and a robust structure for API development, being widely adopted in corporate environments (Persson, 2016; Klochkov and Mulawka, 2021). However, the ease of development provided by the framework can paradoxically favor the adoption of poorly structured implementations. Crucial aspects such as authentication, versioning, documentation, and access control are often neglected in favor of delivery speed, a recurring challenge identified in studies on API management in the industry (Heffner and Vittal, 2017).
The absence of adequate practices can generate significant performance problems, compromising application response time by up to 70% compared to optimized implementations (Klochkov and Mulawka, 2021). Security, in particular, represents one of the most sensitive points in API development, with vulnerabilities related to authentication and authorization among the most exploited in distributed systems (Tanveer et al., 2025). To mitigate such exposures, the adoption of mechanisms such as JSON Web Token (JWT)-based authentication and request rate limiting is widely recognized (Nugraha et al., 2023; Serbout et al., 2023).
Rate limiting, for example, plays a relevant role not only in protecting against abusive use but also in preserving service availability for consumers (El Malki et al., 2022). API performance is directly related to the optimization strategies adopted, with the use of response caching being a consolidated approach to reduce latency and increase the throughput of web systems, avoiding redundant request processing (Mertz and Nunes, 2017). The choice between different caching strategies involves trade-offs between consistency and performance that need to be evaluated (Nishtala et al., 2013; Yang et al., 2021).
API observability in production environments constitutes another growing requirement. Structured logs, response time metrics, and request tracing allow for the identification of bottlenecks, diagnosis of incidents, and guidance for optimization decisions (Kratzke, 2022; Niedermaier et al., 2019). The absence of adequate instrumentation prevents teams from understanding the real behavior of the application under load, making maintenance reactive and costly (Li et al., 2022). Additionally, the adoption of continuous integration and continuous delivery (CI/CD) pipelines contributes to the reliability of the development process, automating test execution and reducing the risk of regressions (Soares et al., 2022; Shahin et al., 2017).
Despite the relevance of these practices, there is a scarcity of studies that evaluate them comparatively and progressively in the same technological context, especially in the Ruby on Rails ecosystem. Most of the literature addresses each practice in isolation, without investigating the trade-offs introduced by joint adoption nor the measurable impact on quality attributes such as performance and maintainability. Given this scenario, the present work aimed to analyze the impact of the progressive adoption of best practices in the development of RESTful APIs with Ruby on Rails, through the implementation and comparative evaluation of three experimental prototypes with increasing levels of technical maturity, considering objective performance metrics and the perception of IT professionals.
2. Material and Methods
The methodology adopted in this study was characterized as a research of an applied nature, with an experimental and qualiquantitative approach. The methodological strategy focused on the implementation of three functional prototypes of RESTful APIs, developed incrementally. This approach allowed for the controlled observation of the effects of the progressive adoption of best practices on measurable quality attributes, such as performance, security, and maintainability (Cajueiro, 2015).
The three prototypes were developed and executed in a controlled local environment. A personal computer with a 12th generation Intel Core i5 processor, 32 GB of RAM, and a 256 GB SSD was used, running the Ubuntu Linux 24.04 LTS operating system. The software versions employed were Ruby 3.3.5 and Ruby on Rails 7.2.3 in API mode, with dependencies managed via Bundler 2.5.16 and PostgreSQL 16.11 database.
Code version control was performed with Git, and the repository was maintained on the GitHub platform, as indicated in Appendix A of the original work. Three prototypes of the same REST API were implemented, intended for article management, differing only by the set of development practices adopted in each.
The application’s domain was kept identical across the prototypes, covering create, read, update, and delete (CRUD) operations on the Article model, composed of “title” and “content” fields. The three databases were populated with 500 article records, generated with the same logic, to ensure parity of volume and data structure between implementations.
Prototype 1 (P1) constituted the reference implementation, developed without authentication, route versioning, automated tests, or documentation. This version represented a scenario of low technical maturity, serving as a basis for comparison with the other developed prototypes.
The Prototype 2 (P2) incorporated intermediate practices widely adopted in corporate environments. Explicit versioning of routes through namespaces was included, a recommended practice for maintaining compatibility between clients and services (Lercher et al., 2023). Authentication based on JSON Web Token (JWT) via service object was implemented, with a 24-hour expiration, widely used for performance and security (Nugraha et al., 2023).
Additionally, Prototype 2 integrated integrity validations in the models and a unique index in the users’ email field. Automated tests were developed with RSpec, covering the main request flows, totaling 18 implemented and validated tests. Interactive documentation was generated by the OpenAPI specification, using the rswag library (Golmohammadi, Zhang, and Arcuri, 2023; Haddad et al., 2022; Nugraha et al., 2023).
Prototype 3 (P3) extended the set of practices of Prototype 2 with advanced performance, protection, and observability mechanisms. Response caching via Redis was implemented on all endpoints, with a five-minute expiration and automatic invalidation on write operations (Mertz and Nunes, 2017; Nishtala et al., 2013).
Request rate limiting was implemented with the rack-attack library at three levels: a limit of 300 requests per five minutes per IP address; a limit of 100 requests per minute per JWT token; and specific protection for the authentication endpoint, restricted to five attempts per minute per IP (Serbout et al., 2023; El Malki et al., 2022).
Structured logs in JSON format were configured to record, at the end of each request, the HTTP method, the path, the status code, the execution time in milliseconds, the authenticated user identifier, and the indication of cache hit or miss (Kratzke, 2022; Niedermaier et al., 2019). A continuous integration pipeline was configured in GitHub Actions to automatically execute tests with each push to the repository (Soares et al., 2022). In Prototype 3, 33 tests were implemented and validated.
Performance tests were conducted with the Apache JMeter 5.6.3 tool, recognized for load testing REST APIs (Ali et al., 2022; Kołtun and Pańczyk, 2020). Each prototype was subjected to three distinct load scenarios, executed sequentially to ensure the isolation of results.
Scenario 1, named Basic Load, simulated ten simultaneous virtual users for 60 seconds, representing normal API usage conditions. Scenario 2, Growing Load, started with one user and progressively scaled up to 50 simultaneous users over 90 seconds, aiming to identify the behavior of each prototype under gradually increasing demand.
Scenario 3, named Request Peak, simulated 100 simultaneous virtual users for 30 seconds, with the purpose of stressing the protection mechanisms and the response capacity of each implementation. The endpoint evaluated in all scenarios was GET /articles, equivalent in functionality in the three prototypes, although with distinct paths.
In Prototypes 2 and 3, each test iteration included a prior authentication request to the POST /api/v1/login endpoint to obtain the JWT token. The metrics collected were: average response time in milliseconds, 95th percentile response time, throughput in requests per second, and percentage error rate (Golmohammadi et al., 2023; Bermbach and Wittern, 2020).
Two distinct electronic questionnaires were applied to Information Technology professionals, using the Google Forms platform. The first questionnaire (Appendix B) was administered between January 29 and February 6, 2026, assessing the perception of 19 professionals on the practices implemented in Prototypes 1 and 2, using a five-point Likert scale, multiple-choice questions, and one open-ended question.
The second questionnaire (Appendix C), reformulated to include Prototype 3, was applied between March 30 and April 10, 2026. This instrument evaluated 25 professionals on the practices implemented in the three prototypes, incorporating real-use scenarios and questions about the perceived adoption cost of advanced practices. A five-point Likert scale, multiple-choice questions, one multiple-selection question, and one free-response question were used.
The execution of tests in a local environment imposed some methodological restrictions. The three Rails servers, the PostgreSQL database, and the Redis server operated simultaneously on the same machine, sharing CPU and memory resources. This condition differs from a production environment, where each service operates on dedicated infrastructure with real network latency between components.
Additionally, the volume of 500 records used in the tests does not represent the typical data scale of production applications. These conditions are inherent to the experimental approach in a controlled environment and are aligned with recognized constraints in the literature on benchmarking APIs in local environments (Ali et al., 2022; Bermbach and Wittern, 2020; Henning and Hasselbring, 2022).
3. Results and Discussion
The implementation of the three experimental prototypes revealed a notable progression in the technical maturity of RESTful APIs, manifested both by the diversity of practices adopted and the comprehensiveness of automated tests. Prototype 1, conceived as a low-maturity baseline, demonstrated the inherent limitations of initial implementations, such as the absence of access control, the difficulty of evolution without breaking contracts, and the lack of automated validations, aspects that compromise the robustness and security of systems in production.
In contrast, Prototype 2 addressed these shortcomings by incorporating consolidated practices in corporate environments. There was a significant increase in automated test coverage, from zero to 18 cases, and the introduction of interactive documentation via Swagger, which facilitates API consumption by other developers. These improvements are crucial for maintainability and collaboration in development teams, as pointed out by Lercher et al. (2023) regarding API evolution.
Prototype 3 further expanded the set of practices, focusing on advanced mechanisms for production operation, such as response caching, abuse prevention, enhanced observability, and continuous integration process automation. Test coverage was expanded to 33 cases, and a continuous integration pipeline was configured in GitHub Actions, ensuring automatic test execution with each code change, which reduces the risk of regressions and accelerates the delivery of quality software (Soares et al., 2022).
Performance tests were carried out using Apache JMeter 5.6.3, subjecting each prototype to three distinct load scenarios: Basic Load, Increasing Load, and Request Peak. These scenarios simulated conditions ranging from normal usage to extreme stress situations, allowing for a comprehensive evaluation of each implementation’s behavior under different demand levels, according to the methodology for load testing REST APIs (Ali et al., 2022).
In Scenario 1, Basic Load, Prototype 1 (without authentication) registered an average response time of 303 milliseconds and a 95th percentile of 349 milliseconds. Its throughput was 31.9 requests per second. Prototype 2 (with JWT authentication) presented an average time of 410 milliseconds and a 95th percentile of 585 milliseconds, with a throughput of 9.5 requests per second. Prototype 3 (with JWT and Redis Cache) had an average time of 453 milliseconds and a 95th percentile of 626 milliseconds, with a throughput of 8.8 requests per second.
In Scenario 2, Increasing Load, Prototype 1 maintained the lowest average response time, with 793 milliseconds, and a 95th percentile of 1,510 milliseconds, achieving a throughput of 32.7 requests per second. Prototype 2 registered an average time of 1,279 milliseconds and 2,462 milliseconds at the 95th percentile, with a throughput of 9.3 requests per second. Prototype 3 presented an average time of 1,354 milliseconds and 2,569 milliseconds at the 95th percentile, with a throughput of 8.9 requests per second.
In Scenario 3, Peak Requests, Prototype 1 continued to be the fastest, with an average response time of 2,807 milliseconds and a 95th percentile of 3,275 milliseconds, achieving a throughput of 34.6 requests per second. Prototype 2 registered an average time of 4,937 milliseconds and 6,411 milliseconds at the 95th percentile, with a throughput of 9.9 requests per second. Prototype 3 had an average time of 5,288 milliseconds and a 95th percentile of 6,590 milliseconds, with a throughput of 9.1 requests per second.
The analysis of performance results demonstrated a null error rate across all prototypes and scenarios, indicating consistent functional stability under load, regardless of the technical maturity level. This finding is relevant, as it suggests that the introduction of best practices did not compromise the fundamental robustness of the API, an essential requirement for production systems (Golmohammadi et al., 2023).
Prototype 1, without authentication, consistently presented the lowest response times and the highest throughput in all scenarios. This superior performance is expected, given that its requests do not incur the additional processing of authentication. In the peak scenario, the difference in average response time between Prototype 1 (2.807 milliseconds) and Prototype 2 (4.937 milliseconds) was approximately 76%, an increase attributable to the overhead of JWT authentication under high concurrency.
This JWT authentication overhead includes the cryptographic validation of the token and the database query for user identification on each request. Such a cost is inherent to the adoption of access control mechanisms and represents an explicit trade-off between security and latency, as discussed by Nugraha et al. (2023). Security, in many production contexts, is a non-negotiable requirement, justifying this additional performance cost.
Prototype 3, which incorporated Redis cache, exhibited slightly higher latency than Prototype 2 in all scenarios, with a difference of approximately 7% in average time under basic load and at peak. This result, which contradicts the expectation of reduced response time due to caching, is explained by the specific conditions of the test environment. In a local environment, PostgreSQL responds to simple queries on 500 records in less than 5 milliseconds.
In this context, the overhead of serialization and communication with Redis, estimated between 1 and 3 milliseconds per operation in a local environment, surpassed the gain obtained by eliminating the database query. This finding is in line with the literature, which indicates that the benefit of caching is more expressive when the database query time exceeds the cache access cost, a condition more common in production environments with remote databases, complex queries, or high data volume (Mertz and Nunes, 2017; Yang et al., 2021).
The simultaneous execution of the three Rails servers, PostgreSQL, and Redis on the same machine introduced competition for CPU and memory resources, which may have amplified the latency differences between the prototypes. This limitation is a recognized factor in the literature on API benchmarking in controlled environments and should be considered when interpreting the results (Bermbach and Wittern, 2020; Henning and Hasselbring, 2022).
The first questionnaire, applied to 19 IT professionals, revealed that 68.4% had more than three years of experience and 89.5% had already developed RESTful APIs. All respondents preferred Prototype 2 for use in professional environments, highlighting the relevance of the incorporated practices. OpenAPI-based documentation obtained the highest average on the Likert scale, with 4.63, followed by JWT authentication (4.47), automated testing (4.42), and route versioning (4.26).
The open-ended responses from the first questionnaire reinforced the preference for Prototype 2, emphasizing better security, structural organization, and preparation for system evolution. Some professionals, however, noted that adopting these practices might require a greater initial development effort, suggesting that the choice should consider the project’s context and objectives, a perception that aligned with the findings of the second questionnaire.
The second questionnaire, applied to 25 professionals with experience profiles similar to the first, included Prototype 3 and real-use scenarios. When asked which prototype they would adopt as a starting point in a professional project, 40% indicated Prototype 2, 24% Prototype 3, and 36% stated that the choice would depend on the context. This pattern indicates that experienced professionals value advanced practices but evaluate them based on the constraints and objectives of each project, a result consistent with the literature on cost-benefit in software engineering (Serbout et al., 2023).
Prototype 3 was considered the most prepared to grow and be maintained by a team by 72% of respondents, while Prototype 2 was pointed out as the best cost-benefit by 64%. This distinction is relevant, as it suggests that professionals perceive a difference between ideal technical maturity and the viability of immediate adoption, indicating that the implementation of advanced practices should be incremental and contextualized.
The real-world scenarios presented in the questionnaire revealed a strong association between practices and problems. Faced with a scenario of an abnormal volume of requests degrading the service, 23 out of 25 respondents identified rate limiting as the most appropriate mechanism. This result is aligned with the literature on the effectiveness of rate control as protection for availability (El Malki et al., 2022).
Similarly, for the investigation of incidents in production, 21 out of 25 respondents indicated structured logs with per-request metrics as the most relevant practice. This corroborates studies that emphasize observability as a critical operational requirement in distributed systems (Kratzke, 2022; Niedermaier et al., 2019). The ability to trace requests and collect detailed metrics is fundamental for diagnosing problems and optimizing performance.
Regarding the caching scenario, 20 out of 25 respondents correctly identified that the greatest benefit occurs in APIs with many users and data that change infrequently. This perception is consistent with the performance results observed in this work and with the specialized literature (Mertz and Nunes, 2017; Yang et al., 2021), reinforcing professionals’ understanding of the ideal conditions for cache application.
The evaluation of Prototype 3’s practices on the Likert scale demonstrated a high degree of agreement among respondents. The CI/CD pipeline obtained the highest average (4.40), followed by response caching (4.32), structured JSON logs (4.32), and the justifiable evolution from Prototype 1 to Prototype 3 (4.32). Authenticated user rate limiting obtained the lowest average (4.04), indicating a lower consensus on this specific strategy.
The lower average for rate limiting per authenticated user may reflect a lesser familiarity of respondents with the architectural implications of this approach compared to IP address control, or the perception that IP-based limiting is sufficient for most contexts. This suggests an area where education and awareness about the nuances of rate limiting strategies can be beneficial for professionals.
Regarding the main obstacle to adopting advanced practices, implementation time was the most cited factor by 52% of respondents, followed by technical complexity (20%), absence of perceived need (16%), and lack of technical knowledge within the team (12%). Concerning the ideal moment to introduce these practices, 44% indicated it would be when the project reached a minimum volume of users, while 28% responded that it depends on the context, reinforcing the idea that progressive adoption is a valued strategy.
In summary, the research demonstrated that the progressive adoption of best practices in RESTful APIs with Ruby on Rails, although introducing a measurable performance overhead, especially with JWT authentication, which increased the average response time by approximately 76% under peak load, is justified by the gains in security, maintainability, and observability. Redis caching, although it did not show gains in the local test environment due to low database latency, is recognized as beneficial in production scenarios. Functional stability was maintained across all prototypes, and the perception of IT professionals reinforces the importance of these practices, indicating that the choice and timing of their implementation should be contextualized and incremental, balancing technical maturity with project viability.
4. Conclusion
This study analyzed the impact of the progressive adoption of best practices on the development of RESTful APIs with the Ruby on Rails framework, through the implementation and comparative evaluation of experimental prototypes and the perception of IT professionals. It was found that the introduction of advanced practices, such as JWT authentication, generated a measurable performance overhead, with an approximate 76% increase in average response time under peak load. However, this latency increase was justified by the gains in security, maintainability, and observability, crucial aspects for production systems. It was observed that all prototypes maintained a null error rate in all load scenarios, demonstrating functional stability. The perception of IT professionals reinforced the importance of these practices, indicating that the most advanced prototype was the most prepared for growth, while the intermediate one offered the best cost-benefit. This demonstrated that the adoption of advanced practices is contextual and progressive, implying a trade-off between technical maturity and immediate viability, which supports an incremental approach in real projects.
The main limitations of this work resided in the execution of tests in a local environment with computational resources shared among services, in the reduced volume of data used in performance tests, and in the size of the samples from the questionnaires applied to professionals. For future studies, it is suggested to replicate the comparison in a production environment with dedicated infrastructure and representative data volume, in addition to evaluating the impact of the cache in scenarios with complex queries and remote databases. It is also recommended to expand the sample of professionals to increase the representativeness of the qualitative data, deepening the understanding of the factors that influence the decision to adopt these practices.
Bibliographic References
Fielding, Roy Thomas. Architectural Styles and the Design of Network-based Software Architectures. University of California, Irvine, 2000.
Golmohammadi, A.; Zhang, M.; Arcuri, A. 2022. Testing RESTful APIs: A Survey. arXiv preprint arXiv:2212.14604, 2023.
Gowda, P.; Gowda, A. 2024. Best Practices in REST API Design for Enhanced Scalability and Security. Journal of Artificial Intelligence, Machine Learning and Data Science, 2024.
Heffner, K.; Vittal, S. 2017. API Management: An Empirical Study of Industry Practices and Challenges. IEEE International Conference on Web Services (ICWS), 2
Klochkov, D.; Mulawka, J. 2021. Improving Ruby on Rails-Based Web Application Performance. Information 12(8): 319.
Pautasso, C.; Zimmermann, O.; Leymann, F. 2008. RESTful Web Services vs. “Big” Web Services: Making the Right Architectural Decision. Proceedings of the 17th International Conference on World Wide Web, 2008.
Persson, K. 2016. Optimizing Ruby on Rails for Performance and Scalability. Tese de Doutorado em Ciência da Computação. KTH Royal Institute of Technology, Estocolmo, Suécia.
Article originating from the Final Course Work of the Specialization in Software Engineering of the MBA USP/Esalq
To learn more about the course, click here and access the MBX Academy platform