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.

15549733b73e060964a336f67ef91bff?s=128

Julia Grace

August 25, 2014
Tweet

Transcript

  1. 8.
  2. 10.
  3. 11.
  4. 12.
  5. 15.
  6. 21.

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

    60% on a city level for the US within a 25 mile radius.” ! @jewelia
  7. 25.

    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
  8. 26.

    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
  9. 27.

    Cons ! We are explicitly introducing latency. ! User pays

    a latency penalty on first visit; this could leave a bad first impression. ! @jewelia
  10. 28.

    When you start using the word penalty to talk about

    a feature, something is very wrong. @jewelia
  11. 36.
  12. 37.

    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
  13. 43.

    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
  14. 45.