public Optional<String> getRunId() {
    DistributedLock runIdLock;
    String runId = null;

    runIdLock = coordinationUtils.getLock(CoordinationConstants.RUNID_LOCK_ID);
    if (runIdLock == null) {
      throw new SamzaException("Failed to create utils for run id generation");
    }

    try {
      // acquire lock to write or read run.id
      if (runIdLock.lock(Duration.ofMillis(CoordinationConstants.LOCK_TIMEOUT_MS))) {
        LOG.info("lock acquired for run.id generation by this processor");
        processorId = clusterMembership.registerProcessor();
        int numberOfActiveProcessors = clusterMembership.getNumberOfProcessors();
        if (numberOfActiveProcessors == 0) {
          String msg = String.format("Processor failed to fetch number of processors for run.id generation");
          throw new SamzaException(msg);
        }
        if (numberOfActiveProcessors == 1) {
          runId =
              String.valueOf(System.currentTimeMillis()) + "-" + UUID.randomUUID().toString().substring(0, 8);
          LOG.info("Writing the run id for this run as {}", runId);
          metadataStore.put(CoordinationConstants.RUNID_STORE_KEY, runId.getBytes("UTF-8"));
          metadataStore.flush();
        } else {
          runId = new String(metadataStore.get(CoordinationConstants.RUNID_STORE_KEY));
          LOG.info("Read the run id for this run as {}", runId);
        }
        runIdLock.unlock();
      } else {
        throw new SamzaException("Processor timed out waiting to acquire lock for run.id generation");
      }
    } catch (UnsupportedEncodingException e) {
      throw new SamzaException("Processor could not serialize/deserialize string for run.id generation", e);
    }
    return Optional.ofNullable(runId);
  }
Generates RunId for Standalone use case
If there is only one processor in the quorum (registered with ClusterMembership) then create new runid and add to store
Else read runid from the store

Steps to generate:
1. acquire lock
2. add self to quorum (register itself with ClusterMembership)
3. get number of processors in quorum
4. if qurorum size is 1 (only self) then create new runid and write to store
5. if quorum size if greater than 1 then read runid from store
6. unlock
samza-core/src/main/java/org/apache/samza/coordinator/RunIdGenerator.java