Skip to main content

Performance & Best Practices

This guide covers strategies for optimizing your use of the SensorUp GraphQL API to achieve the best performance and reliability.

Query Optimization

Request Only What You Need

GraphQL’s strength is precise field selection. Use it: Bad:
Good:
Impact: Reduced payload size by 90%+, faster response times

Use Pagination Appropriately

Don’t request more data than you can display: Bad:
Good:
Recommended page sizes:
  • UI lists: 20-50 items
  • Background processing: 100-500 items
  • Exports: Use export endpoints, not pagination
GraphQL allows querying multiple resources in one request: Bad:
Good:
Impact: Reduced latency by ~66%, fewer round trips

Use Fragments for Reusability

Define reusable fragments for common field sets:

Federation Performance

Understand Query Plans

Cross-subgraph queries require multiple fetches. Minimize hops: Less Efficient:
More Efficient:

Leverage Parallel Execution

Federation executes independent root fields in parallel:
All three subgraphs are queried simultaneously.

Filtering & Searching

Use Server-Side Filtering

Filter on the server, not the client: Bad:
Good:

Specific Lookups vs. List Filtering

Use ID lookups when you know the ID: Less Efficient:
More Efficient:

Caching Strategies

Cache Static Data

Some data changes infrequently:

HTTP Caching

Configure appropriate cache headers:

Application-Level Caching

Use a caching client like Apollo Client:

Rate Limiting & Throttling

Implement Exponential Backoff

When encountering rate limits or errors:

Batch Updates

Instead of many small mutations, batch when possible: Less Efficient:
More Efficient:

Query Complexity

Avoid Deep Nesting

Deep queries can be expensive: High Complexity:
Lower Complexity:

Limit List Sizes

Always use pagination limits:

Monitoring & Debugging

Use Correlation IDs

Include correlation IDs for tracking:

Log Query Performance

Track slow queries:

Monitor Error Rates

Track and alert on error patterns:

Network Optimization

Use Compression

Enable gzip/brotli compression:

Minimize Payload Size

  • Use fragments to avoid duplication
  • Omit __typename if not needed
  • Use aliases to simplify response structure

Connection Pooling

Reuse HTTP connections:

Best Practices Checklist

Query Design

  • Request only needed fields
  • Use pagination (first: 20-100)
  • Apply server-side filters
  • Use specific lookups vs. list queries
  • Batch related queries in one request
  • Use fragments for reusability

Performance

  • Cache static data (profiles, catalogs)
  • Implement exponential backoff
  • Monitor query performance
  • Use correlation IDs
  • Minimize cross-subgraph hops
  • Limit query depth (≤ 4 levels)

Error Handling

  • Check GraphQL-level errors
  • Check mutation-level errors
  • Log errors with context
  • Implement retry logic
  • Handle partial failures gracefully

Security

  • Store credentials securely
  • Rotate API keys regularly
  • Use HTTPS always
  • Validate input data
  • Sanitize user-provided content

Performance Metrics

Target Metrics

Measuring Performance

Common Anti-Patterns

1. Over-fetching

2. N+1 in Application Code

3. Polling Too Frequently

4. Ignoring Errors

Resources

Support

For performance issues or optimization assistance:
  • Review query plans in Apollo Studio
  • Contact your SensorUp account team
  • Provide correlation IDs for specific slow queries