iwex
iwex

Reputation: 393

How to store relatively static data?

I'm interested in the following question: how best to store relatively static data - in the database or in the code, or combine?

For example, we have a list of countries, they do not change every day and on the one hand they can not be saved into the database and stored as an array, numbered manually or even use 2-character country codes.

Next, we now have info from the Google geocoder, we have place_id and the country's bounds, it's also like the unchangeable data.

A little more complicated, now we need to deploy the application on another machine, let's say we have the list of countries, but there is no information from Google, and doing 200+ requests as a certain part of the migration is also not an option ..

And there can be many such examples, some harder, others easier - currencies, languages, different types of something.

I would like to hear some of your approaches, reflections, best practices. Thank you!

Upvotes: 0

Views: 608

Answers (2)

Rick James
Rick James

Reputation: 142316

As soon as you decide to JOIN the static data to a 'dynamic' table, you will be glad to store it in the database.

And, when Yugoslavia or Czechoslovakia splits again, you don't have to edit your code.

Upvotes: 1

Zazaeil
Zazaeil

Reputation: 4119

Definitely in code, unless it grows unmannaged. But event then, you're free to move it out into *json/*xml or whatever-format-you-like-more. Why? Mostly for few reasons: having data locally makes you internet-independent, your code still can run; no delay penalties in terms of connection slowness or similar problems.

Regarding deployment problem. You can always have default json/xml stored in DB as plan "B". In case it's really necessary, you can make a single call to retrieve the default list and then cache it, memorize in any fashion you like more.

To summarize, database is the last thing you'd like to rely on (unless we talk about the data of certain kind, which has to be gathered and managed from the single place - namely, your SQL server).

Upvotes: 0

Related Questions