/dev/docs/replication
Type: /type/page
body: value: This document describes the replication setup for Open Library fastcgi processes and their interations with infobase process for cache invalidation.

The OL fastcgi process maintains state for the following 3 cases.

* compiled templates and macros
* i18n strings
* local cache for most frequently used pages like `/index.*`, `/css/*`, `/js/*`, `/docs/*`, ... etc. 

To maintain consistency of state between all the OL fastcgi processes, modifications happening at each process must be informed to all other.

All the OL fastcgi processes talk to the Infobase lighttpd process for reading and writing the data. So it makes things simple to let the infobase process notify all the OL fastcgi processes about the modifications. 

To support this, a simple http notification mechanism is supported at the infobase process, which makes a HTTP POST request to all specified `http_listeners` and a special URL `/system/invalidate` added to OL fastcgi processes to handle the modification notifications.

In the current setup all the OL fastcgi processes are exposed through single lighttpd process (serving openlibary.org) and it is not possible to send POST request to individual fastcgi processes. A simple [fastcgi multiplexer][fcgi-mx] utility is used to make that possible.

[fcgi-mx]: http://github.com/openlibrary/openlibrary/blob/master/pharos/fcgi_multiplexer.py

Assuming the the fastcgi multiplexer is setup at port 7080 on the machine running infobase process, the following urls are added to`config.http_listeners` to enable notifications.

    config.http_listeners = [
    	"http://localhost:7080/ia331525:9080/system/invalidate",
    	"http://localhost:7080/ia331525:9081/system/invalidate"
    ]
 
The same approach can also be extended to support infobase replication with one writer and multiple reader processes. The writer process can notify the reader processes along with OL fastcgi processes.

One immediately visible disadvantage of this approach is that the writes have to wait until all the http listeners are notified. But it will not be an issue as the rate of writes is quite low.
title: Open Library fastcgi replication