The Architecture of Pinterest's Time Series Database - Goku

1806 views Backend System Design

Pinterest built their own time-series database named Goku because existing databases did not fit their requirements, here is the architecture of it.

Existing OpenTSDB setup

Pinterest used OpenTSDB to hold their time-series data but it didn’t work very well at scale. The two key aspects that hurt them were

  • Long GC Pauses
  • Frequent process crash


  1. OpenTSDB disk-based scans are inefficient
  2. The data stored in OpenTSDB does not have a good compression
  3. OpenTSDB is JSON based and hence very inefficient
  4. OpenTSDB is distributed and for a query that spans multiple shards, it first collects the data in one node and then evaluates the query.

Key Decisions

  1. To make the scan efficient, Goku stores data in-memory
  2. Goku uses Gorilla engine which gives 12x compression
  3. Goku computes a partial response at each shard and then sends it to the proxy; thus doing a minimal data transfer.
  4. Goku uses Thrift Binary protocol, much more efficient than JSON


Goku stores 24 hours’ worth of data in-memory with a configured periodic flush to the disk. The most recent query is fired to this in-memory store for quick evaluation.

Goku is a shared time-series database and each shard may contain data from multiple time series. Each Goku instance holds Bucket Map within which the time-series data resides. Each bucket holds data for a 2-hour window.

The writes on each time-series data go to the bucket map, within which it writes to a mutable buffer. Once the window is done, the buffer becomes immutable.

During a query, the request comes to a Goku Proxy which, if required, fans it out to all the involved shards. Each shard does the computation on its share of data and sends the response back to the coordinator/proxy node.

The coordinator/proxy node aggregates the response and sends it back to the client, thus completing the operation.

Arpit Bhayani

Arpit's Newsletter

CS newsletter for the curious engineers

❤️ by 21000+ readers

If you like what you read subscribe you can always subscribe to my newsletter and get the post delivered straight to your inbox. I write essays on various engineering topics and share it through my weekly newsletter.

Other essays that you might like

Overview of Discord's data platform that daily processes petabytes of data and trillion points

924 views 54 likes 2022-11-14

When a company scales, they adopt microservices and each service typically gets its own independent database. With data ...

How Airbnb designed and scaled its central authorization system - Himeji

2206 views 98 likes 2022-11-07

Authorization plays a critical role in ensuring that the platform is not abused. For example, Instagram ensures that if ...

How Gojek masks and keeps users' phone numbers secure at scale?

2572 views 152 likes 2022-10-31

Do hyperlocal companies like Uber, Ola, Swiggy, Gojek, Zomato, etc share our phone numbers with the delivery people or t...

The architecture of Yelp's in-house Search Engine - nrtSearch

2193 views 81 likes 2022-10-24

Elasticsearch is a great search engine, but Yelp was not happy with its performance, so they built their own HTTP layer ...

Be a better engineer

A set of courses designed to make you a better engineer and excel at your career; no-fluff, pure engineering.

Paid Courses

System Design Masterclass

A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.

1000+ learners

Details →

Redis Internals

Learn internals of Redis by re-implementing some of the core features in Golang.

28+ learners

Details →

Free Courses

Designing Microservices

A free playlist to help you understand Microservices and their high-level patterns in depth.

17+ learners

Details →

GitHub Outage Dissections

A free playlist to help you learn core engineering from outages that happened at GitHub.

67+ learners

Details →

Hash Table Internals

A free playlist to help you understand the internal workings and construction of Hash Tables.

25+ learners

Details →

BitTorrent Internals

A free playlist to help you understand the algorithms and strategies that power P2P networks and BitTorrent.

42+ learners

Details →

Topics I talk about

Being a passionate engineer, I love to talk about a wide range of topics, but these are my personal favourites.

  • v13.7.5
  • © Arpit Bhayani, 2022

Powered by this tech stack.