The problem
I worked on a backend lookup that matched IPv4 and IPv6 addresses to networks. I needed to retain past range data as the network records changed and keep a fallback for lookup failures.
Modelling the lookup
I worked on a snapshot-based model to retain historical ranges and query current records without searching the full history.
I used PostgreSQL’s network types and range operators for matching, and added partial GiST indexes for current IPv4 and IPv6 records. I used concurrent index creation for the existing database.
Caching and fallback
I included negative results in the in-process and Redis caches to avoid querying the database for repeated misses.
On a cache miss, the service queries PostgreSQL. I kept Redis failures from blocking that query and retained the existing MySQL fallback for PostgreSQL lookup failures. I released the PostgreSQL connection after the lookup.