2021年3月3日星期三

django, multi-databases (writer, read-reploicas) and a sync issue

So... in response to an API call I do:

i = CertainObject(paramA=1, paramB=2)  i.save()  

now my writer database has a new record.

Processing can take a bit and I do not wish to hold off my response to the API caller, so the next line I am transferring the object ID to an async job using Celery:

run_async_job.delay(i.id)  

right away, or a few secs away depending on the queue run_async_job tried to load up the record from the database with that ID provided. It's a gamble. Sometimes it works, sometimes doesn't depending whether the read replicas updated or not.

Is there pattern to guarantee success and not having to "sleep" for a few seconds before reading or hope for good luck?

Thanks.

https://stackoverflow.com/questions/66467136/django-multi-databases-writer-read-reploicas-and-a-sync-issue March 04, 2021 at 09:05AM

没有评论:

发表评论