How the Oracle of Bacon WorksEvery couple of weeks the Oracle downloads several database files from one of the Internet Movie Database's FTP sites containing around 2.9 million actors and actresses, around 1.9 million movies and TV shows, and around 400,000 nicknames. The Oracle builds a big map of actors and movies and stores it in a 372 MB database file.
There is a database service running at all times that stores the database file in memory. It is written in C for maximum CPU and memory efficiency. The service handles three different types of requests:
- Find the link from Actor A to Actor B.
- How good a "center" is a given actor?
- Who are all the people with an Actor A number of N?
There are several PHP pages -- one for each of the above types of queries -- that run on the Oracle of Bacon web server, which all connect to the database service using TCP.
The database service uses a breadth-first search (BFS) to find the shortest path between pairs of actors. If you want to dig further into how shortest-path algorithms work, I recommend the textbook by Cormen, Leiserson, Rivest, and Stein as an excellent place to start. Other algorithms textbooks are likely to cover the subject as well, if Introduction to Algorithms isn't available. You may also look at materials that I wrote to explain graph algorithms (including BFS) to Duke undergraduate CS students here.
Whenever the Oracle answers a query, the results are cached so that future requests to link to the same actor will occur more quickly. About 95% of all queries can be served instantly from the result cache. The current contents of the cache (i.e., which actors can be linked quickly) can be found here.