Skip to content

Kafka tombstone record (null value) is delivered as the whole message instead of null #18078

Closed

Description

@basteez

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

For a Kafka tombstone record (value === null), the handler doesn't receive null as payload. It receives the whole message envelope (key, value, headers, offset, timestamp, topic, partition).

KafkaRequestDeserializer.mapToSchema uses data?.value ?? data, so a null value falls back to the message itself:

This makes tombstones look like regular messages with an object payload, which is a problem for compacted topics where a tombstone means "delete this key". A handler doing @Payload() user: User | null gets an object with value: null inside instead.

Minimum reproduction code

Inline below

Steps to reproduce

import { KafkaRequestDeserializer } from '@nestjs/microservices';

const packet = await new KafkaRequestDeserializer().deserialize(
  {
    key: 'user-1',
    value: null,
    headers: {},
    offset: '1',
    timestamp: '0',
    topic: 'users',
    partition: 0,
  } as any,
  { channel: 'users' },
);

console.log(packet.data);
// { key: 'user-1', value: null, headers: {}, offset: '1', timestamp: '0', topic: 'users', partition: 0 }

This is the same path ServerKafka.handleMessage goes through, so an @EventPattern('users') handler sees the envelope as @Payload().

Expected behavior

packet.data is null for a record whose value is null. The full message is still available through KafkaContext#getMessage().

NestJS version

12.1.2

Packages versions

@nestjs/common: 12.1.2
@nestjs/core: 12.1.2
@nestjs/microservices: 12.1.2
kafkajs: 2.2.4

Node.js version

26.7.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Happy to send a PR.

Activity

  1. added a commit that references this issue on Oct 12, 2026
    15f1ac1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions