Database Reference
In-Depth Information
To write through the slaves—or not to write through the slaves—th- hat is the question!
Beingabletosendwriterequeststoeitherthemasteroroneormoreslavesprovidesgreater
flexibilityindeploymentoptions,butchoosingoneovertheotherhasimplicationsthatyou
need to consider.
Writing through a slave will be significantly slower than writing through a dedic-
ated master. There will naturally be higher latency involved when writing through
a slave, due to the added network traffic required to sync and coordinate the data
and activities of the master and slave.
Writing through a slave can increase durability, but this can also be achieved by
configuring the master to replicate changes upon commit. By writing through a
slave, you're guaranteed that there will always be at least two Neo4j instances that
will always be up to date with the latest data (the slave itself, as well as the mas-
ter).Alternatively,orinadditiontothis,durabilitycanbeincreasedbyconfiguring
writesonthemastertobereplicatedouttoaspecifiednumberofslavesuponcom-
mit. Although this occurs on a best-effort basis (via the ha.tx_push_factor
property),theendresultisthatyourdataendsuponasmanymachinesasyouhave
configured. Distributed durability is important, as it provides a greater degree of
confidence that you have the full set of data stored in multiple places, but it comes
at a price.
A load balancer of some sort will be required to ensure that writes are only,
or predominantly, handled by the master. Neo4j doesn't provide any built-in
load-balancing functionality. Rather, it relies on an external mechanism of some
sort to provide this capability. For clients requiring such functionality, HAProxy
( www.haproxy.org ) isapopularchoice.Thelogicaroundwhentoroutetothemas-
ter versus a slave then needs to be built into the load-balancing mechanism, which
can be a tricky proposition. How do you know if something is a read or write re-
quest? There's generally no 100% accurate way to determine this based purely on
traffic.Thisoftenresultsinascenario wheretheapplication itself needstopossess
someknowledgeofwhetheritsactionisclassifiedasareadorwrite,andthenhelp
route the request appropriately.
Whether you write through the master or a slave doesn't have to be an all or nothing de-
cision. It's possible to use a hybrid approach (mostly write to the master, mostly read from
the slaves) if this makes more sense for your system. Be pragmatic about making such de-
cisions. The general recommendation provided to most clients nowadays is to try to ensure
writes are predominantly sent to a master, where feasible, with data subsequently being
Search WWH ::




Custom Search