HPKV Best Practices

Best Practices for Using HPKV

This guide provides recommendations to help you get the most out of HPKV.

API Selection

  • Choose the right API for your use case:
    • REST API: Best for simple, stateless operations and broad framework compatibility
    • WebSocket API: Ideal for high-throughput applications and minimizing latency
    • RIOC: Optimal for ultra-low latency requirements and when using official SDKs
  • Consider your performance requirements: If you need the lowest possible latency, use RIOC with our official SDKs. For standard web applications, REST API might be sufficient.

RIOC Best Practices

  • Timestamp handling: While SDK timestamp methods provide accurate operation timing, local system time is acceptable for most use cases. Choose based on your consistency requirements.
  • Connection management: Implement proper connection pooling and automatic reconnection logic with exponential backoff.
  • Batch operations: Use batch operations when performing multiple related operations to reduce network overhead.
  • TLS configuration: Keep TLS enabled unless you have a specific reason not to (e.g., Enterprise setups with alternative security measures).

Key Design

  • Use meaningful and consistent key naming conventions: This helps in organizing and retrieving data efficiently. For example, use prefixes to group related keys: "user:1234:profile", "user:1234:preferences".
  • Keep keys as short as possible while maintaining readability: Shorter keys consume less storage and are faster to process. However, don't sacrifice clarity for brevity.
  • Consider using prefixes for different types of data: This creates a logical separation and can be useful for range queries if implemented in the future. For example: "product:", "order:", "user:".

Data Modeling

  • Structure your data to minimize operations: Design your data model so that related data can be retrieved or updated in a single operation when possible.
  • Use JSON or other structured formats for complex values: This allows you to store multiple fields in a single key-value pair, reducing the number of keys needed.
  • Consider denormalization: Duplicate some data if it means you can retrieve all necessary information in a single operation. Balance this with storage costs.

Error Handling and Reliability

  • Implement comprehensive error handling: Use the specific error types provided by each SDK (RiocError, RiocTimeoutError, etc.) for better error management.
  • Use exponential backoff for retries: Start with a short delay and increase it exponentially with each retry attempt.
  • Monitor operation latencies: Set appropriate timeout values based on your application's requirements and network conditions.

Security Best Practices

  • Certificate management: Store TLS certificates securely and implement proper certificate rotation procedures.
  • Use secure communication: Always use HTTPS for REST API, WSS for WebSocket API, and keep TLS enabled for RIOC unless specifically not required.
  • API key security: Rotate API keys regularly and ensure they're stored securely. Never expose them in client-side code.

SDK Usage

  • Use string methods when appropriate: For text data, use the provided string methods (e.g., insert_string, get_string) to handle encoding automatically.
  • Keep SDKs updated: Regularly update to the latest versions to benefit from performance improvements and security updates.
  • Utilize SDK-specific features: Take advantage of features like batch operations and connection pooling provided by the SDKs.

Performance Optimization

  • Choose appropriate operation modes: Use batch operations for multiple related operations, and consider using RIOC for ultra-low latency requirements.
  • Monitor and optimize access patterns: Regularly analyze your usage patterns and adjust your data model or access strategies accordingly.