Skip to main content
Tweeted twitter.com/StackWordPress/status/959336773250887681
edited title
Link

Data How to ensure data consistency in Wordpress

Source Link

Data consistency in Wordpress

I'm currently tackling the implementation of a web app with Wordpress.

However, right now, I'm facing what I think is a general issue for everyone trying to implement a wep app with Wordpress. Nonetheless, nobody seems to talk about it.

That issue relates to data consistency. After looking at different sources on the subject and playing for quite a while now with Wordpress code, I have seen no trace of database ACID transactions or any other means to ensure data consistency. Taking into account that a user request might trigger multiple write operations on the database, it seems that such a critical issue might cause data inconsistencies, as something might fail in the middle of a request processing, causing partial writes.

This is something that appears to happen even internally in the Wordpress API functions.

As an example, let's take wp_insert_post (which is a common core API operation). It seems that this function, performs multiple write operations and they do not get executed under the scope of a database transaction. That looks right to me since the transaction lifecycle, from my point of view, should be managed at a higher application layer.

However, no transaction is used, even in higher layers.

What's more, to make things worse, I've seen that wp_insert_post hides the return value of most of the write calls that it performs on the database (such as saving the thumbnail as metadata, categories, tags, etc.).

This fact, might make callers (such as other third party plugins or the wordpress admin pages themselves) think everything has been saved correctly to the database when in fact it's not, preventing them from noticing it, so there would be no way for them to handle the transaction properly (knowing when to commit or rollback) or giving appropriate feedback to users.

Am I missing something? How can one make data, at least, eventually consistent in Wordpress apps?

How can we make sure that, in general, developing a web app with Wordpress, will not lead to a nightmare, trying to manage these kind of data inconsistencies?

Any help in this respect would be really appreciated.