title: How to sync contacts with server contacts in shortest iteration and faster?
body: <p>I have created one application the same as <code>WhatsApp</code> to chat with the same industry people and my basic concept is to sync user contact and find a user who is using this app and users can chat with each other.</p>
  <p>Contact sync I have done in my application and its working fine till 100 to 500 contacts but if any user has 2000 to 3000 contacts in his contact book its taking time to sync with the server.</p>
  <p>I am using the below code to get user contacts and sent them to the server.</p>
  <pre><code>ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
  NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);
  NSMutableArray *contacListAddIntoDatabase = [NSMutableArray new];
  
  for (id record in allContacts) {
      ABRecordRef thisContact = (__bridge ABRecordRef)record;
      //save Contact in DataBase.
  }
  </code></pre>
  <p>After saving all records in the local <code>database</code> i am sending that record to the server to check if that contact is a user of my app and get backlist of users who are using my app. I have implemented paging in <code>contactsync service</code>.</p>
  <p>Here is my contact sync to server code :</p>
  <pre><code>if ([[APP_DELEGATE contactArrayForSync] count] &gt; 0) {
      int long pageSize = ([[APP_DELEGATE contactArrayForSync] count] &gt; CONTACT_SYNC_PAGE_SIZE ) ? CONTACT_SYNC_PAGE_SIZE : [[APP_DELEGATE contactArrayForSync] count];
      NSError *error;
      NSData *jsonData = [NSJSONSerialization dataWithJSONObject:contactList
                                              options:0
                                              error:&amp;error];
      NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
      [[APP_DELEGATE apiManager] syncUserContacts:[APP_DELEGATE getEncryptedUserID] andJSONString:jsonString withCallback:^(BOOL success, id responseObject) {
          //Update DataBase as per server response
      }];
  }
  </code></pre>
  <p>to sync 2000 contacts it's taking around 2min to sync and its very large amount of time to sync contacts.</p>
  <p>I want to reduce this time so is there any way to get sync data in sorter time.</p>
  <p>I am stuck here and the client asking a faster solution to sync my contacts.</p>
  <blockquote>
  <p>Note: In the server, I have around 50000 records in my Contact table and it may increase in the future.</p>
  </blockquote>
  <p>any suggestions will be appreciated.</p>
  <p><strong>UPDATE:</strong> At the first time I am sending all contacts to a server in paging that's fine but after first sync every second sync I need to send only updated or newly added records right now I am sending all record to the server every time.</p>
  <p>so how can I get an updated record or newly added record and faster next time sync also?</p>