Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

A shared library defines an enum Feature and services exchange EnumSet<Feature> values over JSON and Kafka. Services deploy at different times, so a consumer may receive a feature name it does not know. Design the representation and evolution rules.

Keep EnumSet<Feature> inside each service, but put a JSON array of stable feature names on the wire, never ordinals or bit masks. Consumers must tolerate names they do not know by ignoring and counting them, constants are never renamed or removed while they may be in flight or stored, and these rules are configured explicitly in the JSON library, documented in the shared library and enforced by contract tests.

Why this question is asked

When a shared enum crosses service boundaries, the enum stops being an implementation detail and becomes part of a protocol. Services deploy at different times, Kafka keeps old messages for days, and a consumer may be several releases behind the producer. A single new constant can then crash every old consumer, and on a Kafka topic that crash repeats on the same message until someone intervenes. Interviewers ask this to see whether we design for the version skew that always exists in a distributed system. In this answer, we will choose the wire format, make consumers tolerant of unknown names, define how constants may be added, renamed and removed, configure the JSON library deliberately, and turn the rules into tests.

1What Goes Wrong With a Naive Design

A typical starting point is a DTO with a field EnumSet<Feature> features, serialized by Jackson. Jackson writes it as an array of names, such as ["DARK_MODE","EXPORT"], which is already a good wire format. The problem is on the reading side: by default, Jackson fails when it meets an enum value it does not know.

Now picture the deploy. Producer service A ships release 12, which adds Feature.BULK_EDIT and starts sending it. Consumer service B is on release 11. Its deserializer throws on "BULK_EDIT", the Kafka listener's error handler retries the record, and depending on configuration the partition either stalls behind that record or the record goes to a dead letter topic. Either way, B stops processing real work because of a flag it did not even need.

Step throughOne new constant meets an old consumer
Producer v12Kafka topicConsumer v11
{"features":["EXPORT","BULK_EDIT"]}
deliver record at offset 1042
Feature.valueOf("BULK_EDIT") fails
no commit, retry offset 1042
deliver offset 1042 again
fails again: partition stuck

6 messages in order. Play them, or step through them one at a time.

Strict deserialization turns a harmless addition into a consumer outage.

2Choosing the Wire Format

The wire format should be a list of stable names. Ordinals and bit masks are ruled out for the same reason as in a database: they depend on the order of declaration, and the producer and consumer may be compiled against different orders. A bit mask is also unreadable when we inspect a topic during an incident, and limited to 64 features.

Names are readable, independent of order, and survive version skew as long as we never change their meaning. If teams want to rename Java constants freely, each constant can declare an explicit wire name, and Jackson can be told to use it with @JsonProperty on the constant or a @JsonValue method. Semantically the field is a set, so the receiver must not rely on the order of the array, and the producer should not send duplicates.

3Making Consumers Tolerate Unknown Names

The consumer's rule is: an unknown name is information from the future, not an error. We ignore it for business logic, count it in a metric, and keep processing. The most explicit way to do that is to deserialize the wire field as strings and convert at the edge of the service, so the behaviour does not depend on library defaults at all.

Java
record FeatureMessage(String accountId, Set<String> features) {} // wire DTO: plain strings
final class FeatureMapper {
private final Counter unknown; // Micrometer counter: features.unknown
FeatureMapper(MeterRegistry registry) { this.unknown = registry.counter("features.unknown"); }
EnumSet<Feature> toDomain(Set<String> names) {
EnumSet<Feature> result = EnumSet.noneOf(Feature.class);
for (String name : names) {
Feature f = Feature.byWireName(name); // returns null when unknown
if (f == null) { unknown.increment(); log.debug("unknown feature {}", name); }
else result.add(f);
}
return result;
}
}
mapper.toDomain(Set.of("EXPORT", "BULK_EDIT")); // [EXPORT], features.unknown = 1

Notice that the consumer still gets an EnumSet internally, so every business check stays type-safe and fast. The metric matters: a steady count of unknown features right after a producer deploy is expected, but a count that stays high for weeks means a consumer was never upgraded.

Whether ignoring is the right default depends on what a feature means. If a feature enables something, ignoring it degrades gracefully. If a value means restrict this account, ignoring it would weaken a protection, so for such fields we would reject the message to a dead letter topic and alert instead. The library documentation should state this per field.

4Evolution Rules for the Enum

Adding a constant is safe once every consumer tolerates unknown names. Renaming or removing one is not, because messages carrying the old name may still sit in Kafka for the topic's retention period, in a replay, in a dead letter topic, or in a database that stored a copy. So we never rename a wire name, and we never remove a constant that may be in flight or stored.

Removal becomes a sequence. First we deprecate the constant and stop all producers from sending it. Then we wait at least as long as the longest retention among the topics and stores that may hold it, and confirm with a metric or a scan that it no longer appears. Only then do we delete it, and we add its name to a list of retired names that may never be reused for a new meaning. A rename is an addition of the new name plus a removal of the old one, with consumers accepting both in between.

Step throughChanging the Feature enum safely
  1. Adding a new constant?
    YesCheck every consumer tolerates unknown names, then addNoIt is a rename or removal
  2. Deprecate the old constantproducers stop sending it; consumers keep accepting it
  3. Wait out every retention periodtopics, dead letter topics, stored copies
  4. Has the name disappeared from traffic and storage?
    YesDelete it and record it as retiredNoKeep waiting and find the sender
  5. Never reuse a retired namecontract test checks the retired list

5 steps in order. Play them, or step through them one at a time.

5Configuring the JSON Library Explicitly

If we do let Jackson deserialize straight into the enum, we must choose its behaviour on purpose rather than accept the default. Jackson offers DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, which turns unknown names into null, and READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE together with @JsonEnumDefaultValue on a constant such as UNKNOWN. A null inside a set needs care, since EnumSet cannot hold null, and an UNKNOWN constant must then be filtered out of business logic. How Jackson's collection deserializers handle these nulls, and which defaults apply, has changed between Jackson 2 and Jackson 3 (which Spring Boot 4 uses), so check your version.

This uncertainty is the reason to write a test rather than trust documentation. The test feeds the configured ObjectMapper or JsonMapper a payload with a name the enum does not have and asserts the result: no exception, the known names kept, the unknown one counted. The same test runs in every service that consumes the type, because each service configures its own mapper.

6Turning the Rules Into Contract Tests

Written rules are forgotten, so the shared library ships tests that enforce them. One test compares the enum's wire names with a checked-in file of published names and fails if any published name disappeared or changed. Another fails if a retired name is reused. A consumer-side test, provided as a reusable test fixture, asserts that unknown names are tolerated. With consumer-driven contract tools such as Pact, the producer can also verify that every consumer's recorded expectations still pass before it releases a new constant.

The library's README states the rules in a few sentences: names are the wire format, consumers tolerate unknown names, additions are free, removals follow the deprecation sequence, and retired names are never reused. That short document is what new team members read before touching the enum.

7Follow-up questions

Why not make every service upgrade the library before the producer sends a new feature?

Because that turns every addition into a coordinated release across teams, and it still fails for messages already stored or replayed. Tolerant readers let each team deploy on its own schedule. Coordination is reserved for the rare removals.

Should the producer send names the consumer does not need?

Yes, it is fine. The topic is shared, and each consumer picks what it understands. That is the whole point of tolerant readers: the producer does not have to know every consumer's version. If the payload grows too large, that is a schema design question, not a reason to filter per consumer.

What about Avro or Protobuf instead of JSON?

Both have their own enum evolution rules. Protobuf enums are numbers on the wire, so numbers must never be reused and unknown values are preserved as numbers. Avro can declare a default symbol for unknown enum values in the reader's schema. The principle is the same: stable identifiers, tolerant readers, and a schema registry or contract test that checks compatibility before release.

8Conclusion

In this answer, we kept EnumSet<Feature> inside services and sent a list of stable names on the wire. Consumers convert names at the edge, ignoring and counting unknown ones instead of failing, unless the field is a restriction where ignoring would be unsafe. Constants are added freely but renamed or removed only through deprecation, a wait longer than every retention period, and a retired list. We configured the JSON library's unknown-enum behaviour explicitly, tested it in every consumer, and enforced the rules with contract tests and a short README.

What to say in the interviewAbout 90 seconds aloud

Open with

I would separate the in-process type from the wire format. Inside a service, EnumSet<Feature> is efficient and type-safe, but on JSON and Kafka the field is an array of stable names, never ordinals or a bit mask, because producer and consumer may be compiled against different versions of the enum.

Then, if they want more

The key rule is that consumers tolerate names they do not know. With default Jackson settings an unknown enum name fails deserialization, and on Kafka that can stall a partition on one record.

So I would deserialize the wire field as strings and map them to the enum at the edge, ignoring and counting unknown ones with a metric, or, if we bind directly to the enum, configure Jackson's unknown-enum features explicitly and test them, because the details differ between Jackson versions.

If a value restricts something, ignoring would be unsafe, so that field gets a stricter policy.

For evolution, adding constants is free once readers are tolerant, but we never rename or remove a constant that might be in flight or stored: we deprecate it, stop producers sending it, wait out topic retention and any stored copies, then remove it and add the name to a retired list that can never be reused.

I would document these rules in the library and enforce them with contract tests on published names and on unknown-name tolerance.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 4
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A shared library defines an enum Feature and services exchange EnumSet<Feature> values...": https://scrivio-interview-library.netlify.app/java/sets/44620aeeb2/