Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
In order to make this solution work, you’ll need a web stack that can handle many concurrent requests. Reddit’s stack for most microservices is Python 3, Baseplate, and gevent. Django/Flask also work well when run with gevent. gevent is a Python library that transparently enables your microservice to handle high concurrency and I/O without requiring changes to your code. It is the secret sauce that allows you to run tens of thousands of pseudo-threads called greenlets (one per concurrent request) on a small number of instances. It allows for threads handling concurrent duplicate requests to be enqueued while waiting to acquire the lock, and then for those queues to be drained as threads acquire the lock and execute serially, all without exhausting the thread pool.
Pottery — Pythonic Redis utilities, including a distributed lock
This decorator works by forcing the flow of control through a distributed lock on the request hash, ensuring that no two duplicate requests can proceed concurrently. In this example, we’ve used Pottery’s implementation of Redlock (backed by shared Redis instances) which implements Python’s excellent threading.Lock API as closely as is feasible.
Related posts
- Is Redis om production ready? Or will it be production ready anytime soon?
- Python use by SWEs
- Is there any way for hGetAll to return a key-value pair list instead of a simple list?
- Evolving Reddit’s ML Model Deployment and Serving Architecture
- Worth wrapping pottery functions for compliance with async?