Data

KEFCore: Kafka as an Entity Framework Core back-end

DEV Community: #csharp Mario Mastrodicasa
Data

A DEV Community write-up introduces KEFCore, a third-party Entity Framework Core provider that keeps the same DbContext model but stores entities in Apache Kafka compacted topics instead of a relational database, querying them through Kafka Streams.

Key points

  • Introduction: KEFCore is a third-party provider that keeps your DbContext model but uses Apache Kafka as the EF Core back-end.
  • Context setup: BloggingContext inherits from KafkaDbContext, so the provider is configured in OnConfiguring instead of UseSqlServer().
  • Required options: BootstrapServers and DbName are mandatory; ApplicationId and the Streams, Producer and Topic config builders are optional.
  • Storage layout: each entity type becomes a compacted topic named DbName.FullQualifiedDataClassName, e.g. TestDB....Blog.
  • Record format: the Kafka key is the primary key, the value is a JSON string with typeName plus a data array of the property values.
  • Constraints: values are deserialized from the .NET type in the assembly, so changing a property type makes old data unreadable.
  • Performance: start-up and first queries are slow; UsePersistentStorage=true with a persistent state store improves it.

Why it matters

For anyone whose EF Core context currently talks to SQL Server or PostgreSQL, KEFCore is interesting mainly as an architectural experiment: it swaps a relational store for compacted topics and buys Kafka's fan-out, replay and real-time push behaviour without giving up DbSet and LINQ. It is not a drop-in replacement. There is no migration utility from an existing database, the value format is a fixed JSON shape tied to the types in your assembly, and start-up cost is heavy enough that the author recommends persistent storage across runs. Treat it as a way to prototype Kafka-as-cache rather than as a production data store, and check the current state of the project before wiring it into anything you have to support.

Real-world use

  • An EF Core application that wants a distributed cache with real-time updates pushed to subscribers instead of running Redis
  • External Kafka-based applications that consume the entity data a .NET service has written into the topics
  • Query scenarios with related tables that could be resolved with Kafka Streams joins to improve responsiveness

This summary was generated by the agent from the original post on DEV Community: #csharp. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message