private List<String> sortMemberIds(
        GroupSpec groupSpec
    ) {
        List<String> sortedMemberIds = new ArrayList<>(groupSpec.memberIds());

        sortedMemberIds.sort((memberId1, memberId2) -> {
            Optional<String> instanceId1 = groupSpec.memberSubscription(memberId1).instanceId();
            Optional<String> instanceId2 = groupSpec.memberSubscription(memberId2).instanceId();

            if (instanceId1.isPresent() && instanceId2.isPresent()) {
                return instanceId1.get().compareTo(instanceId2.get());
            } else if (instanceId1.isPresent()) {
                return -1;
            } else if (instanceId2.isPresent()) {
                return 1;
            } else {
                return memberId1.compareTo(memberId2);
            }
        });
        return sortedMemberIds;
    }
Sorts members based on their instance Ids if available or by member Ids if not.

Static members are placed first and non-static members follow.

Prioritizing static members helps them retain their partitions, enhancing stickiness
and stability. Non-static members, which do not have guaranteed rejoining Ids, are placed
later, allowing for more dynamic and flexible partition assignments.

@param groupSpec     The group specification containing the member information.
@return A sorted list of member Ids.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/RangeAssignor.java