Best Practices and Patterns
Writing Maintainable, Performant RPC Handlers Following Industry Standards
← Back to Building and Integrating Custom RPC Handlers
Introduction
The difference between a working handler and a production-ready handler lies in adherence to best practices. This section distills lessons from Rippled's codebase and years of RPC API development into concrete, actionable guidelines.
You'll learn code style conventions, common pitfalls to avoid, performance optimization strategies, documentation standards, and maintenance best practices that will make your handlers robust, efficient, and easy to maintain.
Code Style Guidelines
Naming Conventions
Handlers:
// Pattern: doPascalCaseCommandName
Json::Value doAccountInfo(RPC::JsonContext& context);
Json::Value doLedgerRequest(RPC::JsonContext& context);
Json::Value doSubmitTransaction(RPC::JsonContext& context);
// Files: PascalCase.cpp and .h
// Location: src/xrpld/rpc/handlers/AccountInfo.cppHelper Functions:
Member Variables:
Constants:
Formatting Standards
Indentation and Spacing:
Line Length:
Braces Style:
Common Pitfalls to Avoid
Pitfall 1: Trusting Client Input
Pitfall 2: Not Checking Ledger Availability
Pitfall 3: Exposing Implementation Details
Pitfall 4: Ignoring Resource Limits
Pitfall 5: Not Handling Concurrent Access
Pitfall 6: Missing Error Response Fields
Pitfall 7: Silent Failures
Pitfall 8: Not Checking Permission Requirements
Performance Considerations
Ledger Access Optimization
Query Optimization
Memory Efficiency
String Operations
Documentation Standards
Header Documentation
Inline Comments
Documentation Best Practices
Be concise: Avoid verbose explanations
Be accurate: Keep docs in sync with code
Be clear: Use precise language
Be complete: Document all parameters and return values
Example usage: Show common use cases
Maintenance Best Practices
Version Your Handlers
When making breaking changes, implement versioning:
Add Deprecation Warnings
Logging Standards
Configuration Management
Testing for Regressions
Code Review Checklist
Before submitting a handler for review, verify:
Functionality
Security
Performance
Maintainability
Documentation
Testing
Example: Well-Implemented Handler
Conclusion
Best practices and patterns distill years of experience into actionable guidelines that elevate your handlers from working code to production-ready software. Consistent naming, thorough documentation, defensive programming, performance optimization, and security-first thinking create handlers that are maintainable, efficient, and safe. Following these standards ensures your contributions align with Rippled's codebase quality and can be confidently deployed in real-world environments.
Last updated

