How Optimizing Memory Management with LMDB Boosted Performance on Our API Service
Article Summary
Pinterest's API team just freed up 4.5GB of memory per host with a clever database swap. The result? Fewer servers, happier users, and a masterclass in optimization.
The Pinterest engineering team tackled a memory bottleneck in their NGAPI service that handles all first-party client requests. Their multi-process architecture was duplicating configuration data across every process, creating massive memory pressure at scale.
Key Takeaways
- Reduced memory usage by 4.5% per host using LMDB instead of per-process copies
- Increased processes per host from 64 to 66, shrinking overall fleet size
- Evaluated three mmap solutions: Marisa Trie, Keyvi, and LMDB won
- Top 50 config files accounted for 90% of duplicate memory consumption
- Zero latency impact: LMDB reads match native Python lookup speeds
Critical Insight
By switching to memory-mapped databases for shared configuration data, Pinterest reduced memory footprint and increased request capacity per host without any code refactoring or latency penalties.