Skip to content

Support distributing MaxMind databases through a shared filesystem disk #411

Description

@stevebauman

Problem

The location:update command currently downloads the configured MaxMind database directly onto the server's local filesystem.

This becomes problematic when an application runs across multiple API servers:

  • Every server needs access to the same MaxMind database.
  • A database downloaded onto one server is not available to the others.
  • Running location:update on every server sends multiple download requests using the same MaxMind license key.
  • MaxMind limits database downloads to one request per day for a license key, causing the remaining servers to fail.

Proposed solution

Allow the MaxMind database to be published to a shared Laravel filesystem disk, such as S3.

One scheduled server can download the database from MaxMind and publish it to the shared disk. Each API server can then retrieve that shared database into a local cache.

A local copy is still necessary because the MaxMind database reader requires a local filesystem path and cannot read an .mmdb file directly from S3.

Example configuration:

'maxmind' => [
    'storage' => [
        'disk' => env('MAXMIND_STORAGE_DISK'),
        'path' => env('MAXMIND_STORAGE_PATH', 'maxmind/GeoLite2-City.mmdb'),
        'ttl' => env('MAXMIND_STORAGE_TTL', 3600),
    ],

    'local' => [
        'type' => 'city',
        'path' => storage_path('app/maxmind/GeoLite2-City.mmdb'),
    ],
],

Expected behavior

  • Existing local-only installations continue working without configuration changes.
  • When a shared disk is configured, location:update publishes the extracted database to that disk.
  • The server running the update also installs the database locally.
  • Other servers download the shared database into their local cache when it is first needed.
  • After the configured TTL expires, a server checks the shared database's modification time and downloads it only when it has changed.
  • The database is streamed through Laravel's filesystem abstraction so any supported shared disk may be used.
  • MaxMind should only be contacted by the single server responsible for running the scheduled update.

This allows horizontally scaled applications to share one MaxMind download while keeping database lookups local and fast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions