As per me horizontal scalability is good approach...
A. Have mysql-master (may be multi-master for write scalaing) replicating to some number of mysql-slaves.
B. And on each mysql-slave's also run Lighttpd/NginX web server server with php (mean to say a event based websever with FastCGI-PHP). Create index.php in your document-root directory with this minimal content:
php-start-tag
$u = “mysql-read-only-user”;
$p = “mysql-read-only-user-password”;
$db = “database-name”;
$S = “path-of-mysql-socket-file”
$query = stripslashes($_GET["q"]);
if (!$query) {
exit(”NO SQL – Please provide ?q=the-sql-statement in the url”);
}
$cmd = “mysql -u$u -p$p -S$S $db –xml -e ‘$query’”;
$output = passthru(”$cmd”, $stat);
if ($stat != 0) {
header(”HTTP/1.1 500 Internal Server Error”);
exit(”ERROR 500 – Can not process ‘$query’”);
}
php-end-tag
This script is just a small sample using which we can easily query mysql over HTTP and the output as xml. Further to this we can extend this sample script to handle json output and even RESTful operations
C. Use HAproxy to load balance these web apps... And access the mysql data over HTTP like:
http://url/?q=select * from table-name limit 2
This is for read scaling...
D. For write scaling, use mysql-proxy/mmm and distribute write data to all masters evenly. For example, in bi-master, write all odd records to mysql-server-1 and all even records to mysql-server-2, and replication to each other.
The above is for write scaling...
E. The main points here are:
a) Separate your read and write process and treat them separately.
b) You can increase security by implementing web access acl's and database credentials from App layer
c) Add new instances/server to scale horizontally...
F. Believe me, this is very similar to what Yahoo/AOL/CNET guys do to scale read/write for mysql.
--From: Sidh.