Pausing After Adding and Eating
I think we all know the old adage to wait 30 minutes after you eat before going into the water isn't necessary, but the idea is a good one. Sometimes it is best to wait. This applies to adding objects using the API. It is possible that if you add an object (for example using addContacts) and immediately try to update that object, you may receive an error that the object does not exist. "How can this be" you ask yourself. You just added the object successfully and used the object Id that was returned to update the object. Obviously the object exists, you do after all have the object Id.
The answer lies in how Bronto provides performance and redundancy. When you add an object, you are essentially writing to a "master" database in Bronto. That information is then replicated on a "slave" database. This "slave" database is also used when you query or ask for information. This effectively splits the workload between the two databases. However, when you to try to update an object, the application first checks to ensure that the Id you provided is valid. This involves querying the "slave" database.
The Problem
When you add an object and then immediately try to update or use the object, you run the chance that the replication from the "master" database to the "slave" has not occurred yet. Usually, this replication happens almost immediately, but there are times during increased activity in the application when the replication may be delayed.
The Solution
There are a couple of solutions we advise clients to use to resolve this problem. The first is to wait 10 seconds before you try to use or update a new object. In PHP, you could use the sleep() function to accomplish this. You could also try to read the object to ensure information is returned. Either of these approaches should ensure the new object exists on the "slave" database before you try to query for it.
We hope this information helps and please let us know if you come up with a different solution that you would like to suggest.
Andrew Kanes
Support Engineer at Bronto


Comments
Post new comment