Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

JSON Schema Validation in Google Pub/Sub Without Additional Services?

Hello!

We are using Google Pub/Sub for our messaging needs and need to validate the JSON schema of messages before they are published. Our goals and restrictions are:

  • Goals:

    • Validate JSON payloads against a pre-configured schema.
    • Automatically reject (not acknowledge) messages that do not conform to the schema.
  • Restrictions:

    • No additional services or tools should be used (e.g., Cloud Functions, Cloud Run).
    • Messages must remain in JSON format (no transformation to Protocol Buffers).

We are considering enforcing client-side validation by requiring all callers to use a custom library for validation before publishing to Pub/Sub. However, we foresee several challenges:

  1. Development Overhead: The library would need to be maintained and developed in multiple languages (e.g., Node.js, .NET).
  2. Developer Experience: Developers would not be able to use the standard Pub/Sub communication methods, as they would need to go through our library.
  3. Bypass Risk: There is no guarantee that developers will use the library, and they might bypass it and call Pub/Sub directly, avoiding the validation.

Is there a way to achieve JSON schema validation natively within Google Pub/Sub, similar to how it handles Protocol Buffers? If not, what are some best practices to ensure schema validation is enforced under these constraints?

Thank you!

0 2 826
2 REPLIES 2