StatsD at Shopify

Shopify Engineering
5 min readintermediate
--
View Original

Overview

The article discusses the use of StatsD at Shopify, highlighting its effectiveness in tracking custom metrics and improving application performance. It provides insights into how StatsD helps identify issues and validate assumptions in web application behavior.

What You'll Learn

1

How to track cache hits and misses using StatsD

2

Why StatsD is effective for validating assumptions in application performance

3

How to implement custom metrics collection with statsd-instrument

Prerequisites & Requirements

  • Basic understanding of caching concepts
  • Familiarity with StatsD and Graphite(optional)

Key Questions Answered

What are the main benefits of using StatsD at Shopify?
StatsD provides a high-level overview of custom data, allowing Shopify to track cache hits and misses effectively. It also helps in validating assumptions about application performance, enabling developers to make data-driven decisions.
How did StatsD help identify a caching issue at Shopify?
By analyzing StatsD graphs, Shopify identified a specific date when a change negatively affected cache performance. This allowed them to trace the issue back to a git commit and resolve it, restoring normal caching behavior.
What is the purpose of the statsd-instrument client?
The statsd-instrument client is used to collect and send metrics to StatsD. It allows Shopify to record various performance metrics without impacting application performance, maintaining an average of ~5 events sent per request.

Key Statistics & Figures

Average events sent to StatsD per request
~5
This indicates the volume of metrics being collected without impacting performance.
Increase in cache misses
doubled
This was observed due to a bug in cache key generation, highlighting the importance of monitoring cache performance.
Decrease in cache hits
halved
This change negatively affected overall application performance, demonstrating the need for effective metrics tracking.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Monitoring
Statsd
Used for collecting and sending custom metrics in production.
Monitoring
Graphite
The real-time graphing system that StatsD runs on top of.
Monitoring
Newrelic
Used for overall performance monitoring of applications.
Library
Statsd-instrument
A client library for sending metrics to StatsD.

Key Actionable Insights

1
Implement StatsD to monitor cache performance in your applications.
By tracking cache hits and misses, you can identify performance bottlenecks and optimize your caching strategy, leading to improved user experience.
2
Use StatsD to validate assumptions about application performance.
When developing features, leverage StatsD to gather real data on user interactions, which can help you make informed decisions and avoid costly mistakes.
3
Consider using the statsd-instrument library for easy metrics collection.
This library simplifies the process of sending metrics to StatsD, allowing you to focus on application logic while still capturing essential performance data.

Common Pitfalls

1
Failing to properly instrument your application can lead to missing critical performance data.
Without adequate metrics, it becomes challenging to identify performance issues or validate assumptions, potentially leading to poor decision-making.

Related Concepts

Caching Strategies
Performance Monitoring
Custom Metrics Collection