0

I have a set of data associating zipcodes to GPS coordinates (namely latitude and longitude). The very nature of the data makes it immutable, so it has no need to be updated.

What are the pro and cons of storing them in a SQL database vs directly as a JavaScript hashmap? The table resides on the server, it's Node.js, so this is not a server vs browser question.

When retrieving data, one is sync, the other async, but there is less than 10k elements, so I'm not sure whether storing these in MySQL and querying them justifies the overhead.

As there is no complex querying need, are there some points to consider that would justify having the dataset in a database? * querying speed and CPU used for retrieving a pair, * RAM used for a big dataset that would need to fit into working memory.

I guess that for a way bigger dataset, (like 100k, 1M or more), it would be too costly in memory and a better fit for the database.

Also, JavaScript obejects use hash tables internally, so we can infer they perform well even with non trivial datasets.

Still, would a database be more efficient at retrieving a value from an indexed key than a simple hashmap?

Anything else I'm not thinking about?

Buzut
  • 4,875
  • 4
  • 47
  • 54

2 Answers2

1

You're basically asking a scalability question... "At what point do I swap from storing things in a program to storing things in a databse?"

Concurrency, persistence, maintainability, security, etc.... are all factors.

If the data is open knowledge, only used by one instance of one program, and will never change, then just hard code it or store it in a flat file.

When you have many applications with different permissions calling a set of data and making changes, a database really shines.

Teslavolt
  • 113
  • 5
  • Indeed, it's not a yes/no question. Zipcodes to geocodes is public data and not really subject to change. The real question is rather about performance, considering a big dataset, would it still be better in a flat file or would a database would be more efficient to retrieve the value? And what about memory usage? – Buzut Dec 12 '19 at 17:14
0

Most basically, an SQL database will [probably ...] be "server side," while your JavaScript hash-table will be "client side." Does the data need to be persisted from one request to the next, and between separate invocations of the JavaScript program? If so, it must be stored ... somewhere.

The decision of whether to use "a hash table" is also up to you: hash tables are great when you are looking for explicit keys. But they're not the only data-structure available to you in JavaScript.

I'd say: carefully work out all the particulars of your exact situation, and use these to inform your decision. "An online web forum like this one" really can't step into your shoes on this. "You're the engineer ..."

Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
  • Thank you for your answer. I forgot to mention that the JavaScript I am talking about is Node.js, thus server side. – Buzut Dec 13 '19 at 09:02