I have a chat application that already has thousands of users. Servers are located in US(Oregon). Users are distributed across the globe. I have started facing an issue related to slow server response for users in India. I want to set up the same infra in India as well. The major problem is MySQL replication. A new MySQL master is created in India but Master-Master replication is creating problems as the database contains tables with auto-increment id as the primary key. As per my understanding, the following process is being followed
Let's assume auto-increment id is now 1000, time is XXXXXXX000 ms and latency between Oregon and Mumbai region is 200ms
- At XXXXXXX000 ms, Server1(US) is adding a new row in xyz table, and now the auto-increment id is 1001.
- At the same time XXXXXXX000 ms, Server2(Ind) is adding a new row in xyz table, and now the auto-increment id is 1001 on the same table.
- After 200ms, Query executed on Server1(US) is replicated to Server2(Ind) which has auto-increment id as 1001 but failed to execute because the table already has that value.
- Similarly, Query executed on Server2(Ind) is replicated to Server1(US) which has auto-increment id as 1001 but failed to execute because the table already has that value.
One of the solutions I found was to set auto_increment_increment and auto_increment_offset values on both the hosts as defined http://www.clusterdb.com/mysql-cluster/setting-up-mysql-asynchronous-replication-for-high-availability. I was able to replicate that but I am not sure whether this is the right approach for a production setup on AWS EC2. Any suggestions would be appreciated.
<ul>
<li> You have wrong answers</li>
<li>The answers are long and difficult to understand</li>
<li> You don't have an answer marked as correct</li>
</ul>