Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Confluent Schema Registry Api Laravel Package

mateusjunges/confluent-schema-registry-api

PHP 7.4+ client for Confluent Schema Registry REST API. Provides high-level sync/async helpers plus low-level PSR-7 request builders, Avro schema support, and optional caching integration for fetching, registering, and managing schemas.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Laravel Integration: The package aligns well with Laravel’s event-driven architecture (e.g., queues, listeners) by providing a synchronous/asynchronous API for schema operations. This enables seamless validation of Kafka events (e.g., order_created) against registered schemas before processing.
  • Microservices Schema Governance: Supports cross-service schema consistency in polyglot Laravel microservices (e.g., PHP + Kafka + Java services) by centralizing schema management via Confluent’s registry. Integrates with Laravel’s service container for dependency injection.
  • Avro/Protobuf Support: Leverages flix-tech/avro-php for schema parsing, which is critical for Laravel apps using Kafka Avro serialization (e.g., via rdkafka or laravel-kafka). Ensures compatibility with Confluent’s schema evolution rules.
  • PSR-7 Compliance: Built on Guzzle 7+, the package adheres to PSR-7 standards, making it easy to integrate with Laravel’s HTTP stack (e.g., Illuminate\Http\Client) or custom middleware for schema validation.

Integration Feasibility

  • Laravel Service Provider: Can be bootstrapped as a Laravel service provider to bind the PromisingRegistry/BlockingRegistry to the container, enabling dependency injection in controllers/jobs.
    // app/Providers/SchemaRegistryServiceProvider.php
    public function register() {
        $this->app->singleton(PromisingRegistry::class, function ($app) {
            return new PromisingRegistry(
                new Client(['base_uri' => config('kafka.schema_registry_url')])
            );
        });
    }
    
  • Queue Workers/Jobs: Ideal for asynchronous schema validation in Laravel queue jobs (e.g., processing Kafka events). The PromisingRegistry allows non-blocking schema checks before publishing events.
  • API Request Validation: Can validate incoming API requests (e.g., Illuminate\Validation) against schemas stored in the registry, ensuring consistency between HTTP payloads and Kafka topics.
  • Event Listeners: Useful for post-publish validation of Kafka events (e.g., after order_created is published, verify its schema matches the registry).

Technical Risk

Risk Area Mitigation Strategy
Async API Complexity Use BlockingRegistry for synchronous workflows (e.g., API validation) and PromisingRegistry for background jobs. Document clear use cases.
Schema Evolution Leverage Confluent’s built-in schema compatibility checks. Add Laravel middleware to reject incompatible schemas.
Caching Overhead Start with CachedRegistry in development; monitor cache hit ratios before enabling in production.
Dependency Updates Pin guzzlehttp/promises to ^2.0 and avro-php to ^4.1 in composer.json to avoid breaking changes.
Error Handling Wrap registry calls in Laravel’s try-catch blocks and log SchemaRegistryException via Monolog.
PHP 8+ Requirement Ensure Laravel app uses PHP 8.1+ (LTS) and update composer.json to enforce this.

Key Questions

  1. Schema Registry Hosting:
    • Will the registry run on Confluent Cloud (managed) or self-hosted (e.g., Kafka + Schema Registry on-prem)? This affects caching, latency, and cost.
  2. Schema Evolution Strategy:
    • Does the team need custom compatibility rules beyond Confluent’s defaults (e.g., strict backward compatibility)? If so, extend the AvroSchema class or use middleware.
  3. Performance Requirements:
    • For high-throughput apps (e.g., 10K+ events/sec), will caching (e.g., Redis via Psr16CacheAdapter) be critical? Benchmark CachedRegistry vs. direct API calls.
  4. Testing Strategy:
    • How will schema registry interactions be tested? Use the package’s integration tests (Docker-based) or mock PromisingRegistry in unit tests.
  5. Monitoring:
    • Should schema registry latency/metrics be exposed via Laravel’s Prometheus or Datadog integrations? Add middleware to track schemaId/subject lookups.
  6. Fallback Mechanism:
    • If the registry is unavailable, should Laravel fail gracefully (e.g., queue events for later) or reject requests? Implement a circuit breaker (e.g., spatie/flysystem-circuit-breaker).

Integration Approach

Stack Fit

  • Laravel Core:
    • Service Container: Bind the registry to Laravel’s DI system for easy access in controllers, jobs, and listeners.
    • Validation: Use the registry to validate API requests (e.g., Illuminate\Validation\Rule) or Kafka payloads.
    • Events: Attach listeners to KafkaEventPublished or JobProcessed to validate schemas post-publication.
  • Kafka Integration:
    • Producers: Validate schemas before publishing events (e.g., in App\Jobs\PublishKafkaEvent).
    • Consumers: Validate schemas on consumption (e.g., in App\Listeners\HandleKafkaEvent).
  • Caching Layer:
    • Use Redis (via Psr16CacheAdapter) or Doctrine Cache for CachedRegistry to reduce registry API calls.
    • Cache schema IDs by hash (default: md5((string) $schema)) or override with sha1 for consistency.

Migration Path

  1. Phase 1: Proof of Concept (PoC)
    • Install the package and test basic operations (e.g., register, schemaForId) in a local Kafka/Laravel setup.
    • Verify compatibility with existing Avro schemas and Laravel’s rdkafka/laravel-kafka packages.
  2. Phase 2: Core Integration
    • Bind the registry to Laravel’s service container.
    • Add schema validation to API requests (e.g., StoreOrderRequest) and Kafka producers.
  3. Phase 3: Performance Optimization
    • Enable CachedRegistry with Redis and measure cache hit ratios.
    • Implement circuit breakers for registry failures (e.g., retry 3x, then queue events).
  4. Phase 4: Monitoring & Governance
    • Add logging for schema operations (e.g., SchemaRegistry::register() calls).
    • Integrate with Laravel’s Prometheus or Datadog for metrics.

Compatibility

Component Compatibility Notes
Laravel Works with Laravel 8+ (PHP 8.1+ recommended). Tested with guzzlehttp/guzzle v7+.
Kafka Clients Compatible with rdkafka (PHP extension) or laravel-kafka for Avro serialization.
Caching Backends Supports Redis, Doctrine Cache, or PSR-16/PSR-6 adapters.
Schema Formats Primarily Avro (via avro-php). Protobuf support requires additional adapters.
Confluent Schema Registry Tested with Confluent Platform 5.2+. Ensure API endpoints match your registry version.

Sequencing

  1. Prerequisites:
    • Set up a Confluent Schema Registry (self-hosted or Confluent Cloud).
    • Configure Kafka topics with schema references (e.g., order-eventsorder-value subject).
  2. Laravel Setup:
    • Add dependencies:
      composer require flix-tech/confluent-schema-registry-api guzzlehttp/guzzle doctrine/cache
      
    • Configure config/kafka.php with registry URL and caching settings.
  3. Core Integration:
    • Create a service provider to bind the registry.
    • Add schema validation to API controllers and Kafka jobs.
  4. Advanced Features:
    • Implement caching (Redis) for high-throughput scenarios.
    • Add middleware for global schema validation (e.g., ValidateKafkaSchema).
  5. Testing:
    • Run integration tests with Docker (as per the package’s make phpunit-integration).
    • Mock the registry in unit tests for isolated validation logic.

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor guzzlehttp/promises (v2.x) and avro-php (v4.x) for breaking changes. Use composer why-not to assess risks.
    • Pin major versions in composer.json to avoid surprises:
      "require": {
        "flix-tech/confluent-schema-registry-api": "^9.0",
        "guzzlehttp/promises": "^2.0",
        "flix-tech/avro-php": "^4.1"
      }
      
  • **Schema Registry Updates
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony