Designing model/database for distance between any two locations (that may change)

Posted by Yo Ludke on Stack Overflow See other posts from Stack Overflow or by Yo Ludke
Published on 2012-12-13T10:44:23Z Indexed on 2012/12/13 11:04 UTC
Read the original article Hit count: 230

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?

© Stack Overflow or respective owner

Related posts about sql

Related posts about ruby-on-rails