This project will serve many duplicate requests with location-specific answers. I.e. 10,000 people in New York will all get the same server response (a list of businesses in New York), but one person in Atlanta will get completely different data (businesses in Atlanta).

Planned architecture:

1. In memory cache which stores the most recent answer for each location. Answers expire every few minutes and an updated answer from the database is loaded.

2. Relational Database stores all the actual business data to make answers.

How can I group cache results by location?

1. Each database row could know which city the business is in, and users would need to pick their city from a list. Then I would have a separate result cache for each city.

2. I could just take the user's lat/long and store the lat/long of every business in the database row and do a location query. I do not know how much cacheing I could do with that approach. Maybe see if I've answered a request within 20 miles of the query location, re-use that response? This avoids having to group things ahead of time but is less accurate.

This seems like a common problem. Is one of these approaches preferred (or something different altogether)? The table in question will have ~100k records worst case, so is this cacheing overkill anyway? Planning to use AWS if that changes anything, or if they have tools for this I should be aware of.

  • Wouldn't the Atlanta location simply be a cache miss? – Robert Harvey Jan 20 '18 at 19:03
  • Sure, and I can handle cache misses I'm just more interested in how to organize the data. Grouping cache items by city vs not grouping them by lat/lon as in OP example. Better results with the former but then I have to manage a list of all the cities I want to support. Have you seen a good answer to that problem before? – Matthew Jan 20 '18 at 19:09
  • A good answer to the problem of managing a list of cities to support? Use a database. Include a City field in your table schema. Group on the City field. – Robert Harvey Jan 20 '18 at 19:14
  • I'm sorry, I am not being very clear. The problem is how best to cache results for different locations. I'm not convinced that giving each row a city field is the best approach (because then you have to manage them by hand). Do you think of other ways to do that which would work/be easy to maintain? For example doing the lat/lon lookups described in my original question, this would mean we do more math at query time but don't have to manage exact cities. – Matthew Jan 20 '18 at 19:21
  • Sounds like a reasonable approach to me. – Robert Harvey Jan 21 '18 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.