Busbud Backend coding challenge submission  

# Busbud Coding Challenge

## Overview
The app is live here: https://radiant-thicket-3612.herokuapp.com/suggestions


### About the code
I chose not to use a framework like Express or Sails.
The purpose is to provide only one single url for sugestions, i think it is not necessary to use anything other than the http module.

My approach for database is to load all cities in memory. The current number of cities allow to be stored in memory on application launch. So the database is unnecessary for the moment.

For performaces and scalability, I opted for a cache system queries (1H00 ttl) using memcached and i work with nodejs in cluster mode to take the full power of the instances.

### Things that could be improved
- In case the application would work with a number of much larger cities. Each worker working with its space of memory, it may be possible and meaningful to work with a databas like mongodb or couchdb to limit the memory usage of each worker.
- I think a re write with go and goroutines give better performance.

### Suggestions scoring
Each Cities are scored based on 3 criterions:
- The city's size by population
- The difference beetwen the search query and the city name
- The distance base on haversine formula
The weighted of these criterion is the final suggestion score and provide by helper calculate_score.js.

### Caching
- For all requests, a check of the availability of memecache is made with a boolean. This is to minimize the impact on the response time that can lead to a connection attempt failed.
  If memecache is declared down for a cluster, the current request and all others for thie worker concerned will use the normal flow of suggestions.

## Testing
The tests are located in `test/suggestions.js` and can be run with `npm test`.
I made a few additions to the test suite like ensure the data is loaded.