Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mapping IP Address to Physical Location

Mapping IP Address to Physical Location

This talk goes over several options for mapping IP address to country (client side, server side, etc.) that I have used in a large scale, production in a web application.

Julia Grace

August 25, 2014
Tweet

More Decks by Julia Grace

Other Decks in Programming

Transcript

  1. IPinfoDB ! “Over 99.5% on a country level and around

    60% on a city level for the US within a 25 mile radius.” ! @jewelia
  2. Dancing with the devil ! Set the country in the

    session based of X_FORWARDED_FOR ! If there is no country in session, then query IPinfoDB once. Put very strict timeouts and no retries on this. ! If the query fails then don’t show country specific info. ! @jewelia
  3. Pros ! We have country info! ! Could cache the

    IP/Country info in Redis for fast future lookups. ! How often should we update? How often does IP/Country data change? @jewelia
  4. Cons ! We are explicitly introducing latency. ! User pays

    a latency penalty on first visit; this could leave a bad first impression. ! @jewelia
  5. When you start using the word penalty to talk about

    a feature, something is very wrong. @jewelia
  6. Pros ! Client side is great for IP based rate-limiting

    and throttling! ! (If all of your users are coming from different IPs, which most are, versus your server which likely has 1 IP) @jewelia
  7. Pros ! Uses MaxMind GeoIP database. ! Unix package (available

    via apt-get or aptitude). ! Updated nightly! ! $geoip_country_code — two-letter country code, for example, "RU", "US". ! ! Nginx caches all supplied databases in memory. The country database is small, roughly 1.4M @jewelia