public void compare() throws SQLException {

    //get the list of accounts from zk in the form of map account id -> account json (as string)
    long startTimeMs = SystemTime.getInstance().milliseconds();
    Map<String, String> accountMapFromZK = fetchAccountMetadataFromZK();
    if (accountMapFromZK == null) {
      logger.info("Account metadata in ZK is empty");
      return;
    }
    long zkFetchTimeMs = SystemTime.getInstance().milliseconds();
    logger.info("Fetched account metadata from zk path={}, took time={} ms", fullZKAccountMetadataPath,
        zkFetchTimeMs - startTimeMs);

    Set<Account> accountSetFromZK = new HashSet<>();
    ObjectMapper objectMapper = new ObjectMapper();
    try {
      for (String accountJson : accountMapFromZK.values()) {
        accountSetFromZK.add(objectMapper.readValue(accountJson, Account.class));
      }
    } catch (IOException e) {
      logger.error("Failed to deserialize account metadata json string from zk to Account object", e);
      throw new SQLException(e);
    }

    // Query the list of all Account from mysql along with their containers
    Set<Account> accountSetFromDB = new HashSet<>();
    for (Account account : mySqlAccountStore.getNewAccounts(0)) {
      AccountBuilder accountBuilder =
          new AccountBuilder(account).containers(mySqlAccountStore.getContainersByAccount(account.getId()));
      accountSetFromDB.add(accountBuilder.build());
    }

    // Compare accounts in ZK and DB
    AccountUtils.compareAccounts(accountSetFromZK, accountSetFromDB);
  }
Compares db with zk and prints the accounts (IDs) that are different
ambry-tools/src/main/java/com/github/ambry/account/MySqlAccountsDBTool.java