< Back

Best Practices

These best practices help you build secure, efficient, and resilient applications using Health Gorilla APIs. They apply across use cases such as Patient360 retrieval, Clinical Alerts, document search, and lab ordering.

Optimize API Performance

  • Use precise search parameters. Filter by fields such as date, type, or status to reduce response size and improve query speed.
  • Paginate large results. Use the link.relation = "next" value in the response bundle to retrieve additional pages of results.
  • Avoid unnecessary polling. Use FHIR Subscriptions or scheduled queries to minimize load and improve efficiency.

Manage Authentication Securely

  • Rotate credentials regularly. Periodically update your client_id and client_secret in accordance with your organization’s security policy.
  • Protect tokens. Store access tokens securely in a server-side vault. Do not expose them in client-side code.
  • Monitor token expiration. Access tokens expire after one hour. Automatically renew tokens using the client credentials flow.

Handle Errors and Retries Robustly

  • Retry transient errors. For status codes like 429, 500, 503, and 504, implement exponential backoff with capped retries.
  • Log error details. Capture OperationOutcome responses and X-HG-Request-ID headers to support debugging and incident response.
  • Avoid retry storms. Implement retry limits to prevent cascading failures during outages or rate limiting.

Monitor and Audit Usage

  • Track critical API operations. Log all authentication attempts, FHIR queries, patient lookups, and webhook events.
  • Respond to webhooks promptly. Return HTTP 2XX within 5–10 seconds to avoid retries.
  • Audit group enrollment. Periodically verify group membership for patients enrolled in alerting or cohort-based queries.

Scale Thoughtfully

  • Batch operations when available. Use batch APIs (such as Group enrollment) to reduce overhead.
  • Stagger queries. Distribute queries for large patient panels to avoid spikes in load or rate-limit violations.
  • Use asynchronous workflows. For high-volume jobs (such as Patient360 data aggregation), use async endpoints when supported.