This is the continuation post of my previous post “Advanced Database classes for WordPress“. Please read that post before continue unless you are not familiar with advanced database classes for WP.

Well, it’s time to see some configurations and ideas about how Hyper-DB or relevant DB classes might help you to scale.

There are a bunch of examples and explanations about the configuration on the db-config.php file.

Master-Slave Different Machines

Multisite Example

Multisite blog tables are something like “wp4_posts” and the example above says that “hey this table belongs to a blog, send queries to blog dataset”

You can add some logic there, let’s say first 1000 blogs use blogset1 1000-2000 use blogset2 and goes on… (this is a terrible idea, there are some logic that makes this process better)

Another use case; imagine you are hosting one of the enterprise websites on your multisite. ( hosts TechCrunch). You might want to use separate dataset for enterprise customers. So, check the blog id, and return different dataset.

BuddyPress and HyperDB

Let’s say you have a successful social network top on the BP. Something like this config will help you to split data between WP and BP.


In this case, we are sharding REST request to a different dataset.

Use a table from another DB

The configuration like above, you can use a totally different database from another dataset for a table. Let’s say you are holding a large amount of trivial data, you probably don’t want to keep your main dataset busy. (Of course, we can use callback there too, just want to show add_table works)


HyperDB is a battle-tested and production-grade abstraction layer of the database calls. It’s flexible enough to handle scaling problems out of the box. But careful when planning the sharding scenario across the multiple datasets especially on multisite. (remember Barry’s talk again)

I saw so many wrong assumptions when people try to use this plugin. This is not a normal plugin, as mentioned its description it’s an “advanced database class”. I hope these examples help.

Also, I highly recommended LudicrousDB instead of HyperDB for the new installations.

I just remembered old glories days of the Zend_Db_Table …Which also supports different RDBMS


Published by Mustafa Uysal

troubleshooter at WPHandle and full-stack developer at the largest Turkish recipe website (#NYT)

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: