Designing model/database for distance between any two locations (that may change)
- by Yo Ludke
We should create a web app which has a number of events each with a location (created as user-generated content, so the number of events will be increasingly large).
The distance between any events should be available, for example to determine the top 5 closest events and such things.
Users may change the locations of events.
How should one design the database/model for this (in a scalable way)?
I was thinking of doing it with a "distance table" (like so http://www.deutschland-tourist.info/images/entfernungstabelle.gif). Then every time, if a location changes, one row and one column have to be recalculated (this should be done with a delayed job, because it is not important to have the changes instantly). Possible problems in Scaling: Database to large (n² items for n events), too much calculation to be done. For example we should see if this is okay for 10.000 users. If each has created just one event, then this would be 100 million integers...
Do you think this would be a good way to do it efficiently? How could one realize such a distance table with an rails model? Is it possible with a SQL databse?
Would you start other approaches?