Skip to main content

Securely Handling Didit Webhooks in Kotlin Microservices

Learn to integrate Didit webhooks securely within a Kotlin microservice architecture. This guide covers best practices for signature verification, timestamp validation, and robust error handling to ensure data integrity and.

Securely Handling Didit Webhooks in Kotlin Microservices

Contents

In this guide

Jump to the part you need.

Robust Security is ParamountImplementing stringent security measures like HMAC-SHA256 signature verification and timestamp validation is crucial for protecting webhook endpoints from tampering and replay attacks in a microservice environment.

Asynchronous Processing Enhances ScalabilityLeveraging asynchronous message queues (e.g., Kafka, RabbitMQ) for processing incoming webhooks prevents bottlenecks and ensures your microservices can handle fluctuating loads efficiently without dropping critical identity verification notifications.

Idempotency Prevents Duplicate ProcessingDesigning webhook handlers to be idempotent is vital to avoid unintended side effects from duplicate messages, which can occur due to network issues or retry mechanisms inherent in distributed systems.

Didit Simplifies Secure IntegrationDidit provides clear documentation and robust webhook mechanisms, enabling seamless and secure integration of real-time identity verification results into your Kotlin microservices. This ensures timely updates for processes like ID Verification and AML Screening.

In today's fast-paced digital world, real-time data processing is no longer a luxury but a necessity, especially when it comes to identity verification. Webhooks serve as the backbone for such real-time communication, allowing services to notify each other instantly about events. When integrating a powerful identity verification platform like Didit into a Kotlin microservice architecture, securely handling these webhooks is critical for data integrity, system reliability, and overall security.

Didit's webhooks provide instant notifications on the status of identity verification sessions, including outcomes from processes like ID Verification, Passive & Active Liveness checks, and AML Screening. This guide delves into the best practices for building a secure and scalable webhook consumer in Kotlin, ensuring your microservices can reliably react to Didit's verification results.

The Importance of Secure Webhook Handling

Webhooks, by their nature, are external HTTP calls to your application. Without proper security measures, they can become a significant attack vector. Malicious actors could attempt to send forged requests, replay old requests, or flood your endpoints, leading to data corruption, unauthorized actions, or denial of service. For sensitive operations like identity verification, where data from Didit's ID Verification or AML Screening is involved, security is non-negotiable.

The core security principles for webhooks revolve around:

  1. Authentication: Verifying that the request indeed originated from Didit.
  2. Integrity: Ensuring the payload hasn't been tampered with in transit.
  3. Timeliness: Protecting against replay attacks where old, legitimate requests are resent.

Didit addresses these concerns by signing its webhooks with an HMAC-SHA256 signature, which you can verify using your unique Webhook Secret Key. This signature, along with a timestamp, provides a robust mechanism to authenticate the sender and ensure message integrity.

Implementing Signature Verification in Kotlin

The first and most critical step in processing Didit webhooks is verifying the HMAC-SHA256 signature. This ensures that the webhook payload was sent by Didit and has not been altered. Didit's documentation provides clear examples for various languages, and the principles translate directly to Kotlin.

Here's a conceptual outline for signature verification in a Kotlin Spring Boot application:

1. Capture Raw Body: It's crucial to obtain the raw request body BEFORE any JSON parsing occurs, as the signature is calculated over the exact bytes of the payload. In Spring Boot, you might need a custom filter or use @RequestBody String rawBody.

2. Extract Signature and Timestamp: Didit sends these in headers (e.g., X-Signature and X-Timestamp). You'll need to retrieve them from the incoming HTTP request.

3. Reconstruct Signed Payload: The string to sign typically combines the timestamp and the raw request body. For Didit, the format is usually t={timestamp}.{raw_body}.

4. Calculate Expected Signature: Use your DIDIT_WEBHOOK_SECRET to compute the HMAC-SHA256 hash of the reconstructed payload. The secret key is obtained from the Didit Console under Settings → API Keys.

5. Compare Signatures: Compare your computed signature with the one received in the X-Signature header. Use a constant-time comparison to prevent timing attacks.

Additionally, you must validate the timestamp. Ensure the webhook was sent recently (e.g., within 5 minutes) to prevent replay attacks. If the timestamp is too old or in the future, reject the request.

Designing for Scalability: Asynchronous Processing

In a microservice architecture, directly processing every incoming webhook synchronously can lead to performance bottlenecks. A sudden surge in Didit verification requests could overwhelm your service, causing timeouts and dropped webhooks. The solution is to decouple webhook reception from processing using an asynchronous message queue.

When a webhook arrives:

1. Your webhook endpoint performs quick, essential validations (signature, timestamp) and then immediately publishes the raw, verified payload to a message queue (e.g., Kafka, RabbitMQ, AWS SQS).

2. A separate consumer microservice (or multiple instances of it) subscribes to this queue, picks up messages, and executes the business logic (e.g., updating user status based on ID Verification results, triggering further AML Screening actions).

This approach offers several benefits:

  • Resilience: If your processing service goes down, messages remain in the queue, waiting to be processed once the service recovers.
  • Scalability: You can independently scale the number of consumers based on demand.
  • Decoupling: The webhook receiver doesn't need to know the intricate details of how the data is processed.

Ensuring Idempotency for Reliability

Distributed systems are prone to network issues, and webhooks might be delivered multiple times. To ensure your system behaves correctly even with duplicate deliveries, your webhook handlers must be idempotent. This means that processing the same webhook payload multiple times should have the same effect as processing it once.

Strategies for achieving idempotency:

  • Unique Identifier: Each Didit webhook typically includes a unique session_id. Store this ID in your database and check if it has already been processed before taking action.
  • Transaction Management: Wrap your processing logic in a database transaction.
  • State Management: Design your state transitions carefully. For example, if a user's verification status changes from 'Pending' to 'Approved' based on a Didit webhook, receiving the 'Approved' webhook again should not cause any issues if the status is already 'Approved'.

By implementing idempotency, you can safely retry webhook processing without worrying about unintended side effects, which is crucial for maintaining data consistency across your services, especially when dealing with critical identity verification statuses from Didit's various products.

Error Handling and Monitoring

Even with the best design, errors will occur. Robust error handling is vital for a production-ready webhook consumer. Implement comprehensive logging, alert mechanisms, and dead-letter queues (DLQs) for unprocessable messages.

  • Logging: Log all incoming webhooks (after verification) and any errors during processing. Include relevant Didit session_id and error details.
  • Alerting: Set up alerts for failed signature verifications, timestamp mismatches, or repeated processing failures.
  • Dead-Letter Queues: Messages that consistently fail processing can be moved to a DLQ for manual inspection and reprocessing, preventing them from blocking the main queue.

Monitoring your webhook endpoint's performance, error rates, and queue lengths will provide insights into the health of your system and allow you to proactively address issues, ensuring smooth processing of all Didit verification results.

How Didit Helps

Didit is engineered to be developer-first, providing clean APIs and robust webhook mechanisms that simplify integration into any architecture, including complex Kotlin microservices. Didit's modular identity platform allows you to compose verification workflows tailored to your needs, whether it's for ID Verification, Passive & Active Liveness, 1:1 Face Match, AML Screening & Monitoring, or Age Estimation.

With Didit, you get:

  • Secure Webhooks by Design: Didit provides signed webhooks with clear documentation on how to verify them, reducing your security implementation burden.
  • Comprehensive Identity Verification: A wide array of products, from ID Verification (OCR, MRZ, barcodes) to NFC Verification (ePassport/eID), all integrated seamlessly.
  • AI-Native Accuracy: Leveraging advanced AI for features like Passive & Active Liveness detection to combat fraud and deliver highly accurate results.
  • Flexible Workflows: Define custom verification journeys using the no-code Business Console, ensuring you only get the data you need for each user.
  • Cost-Effective Solutions: Didit offers Core KYC and a pay-per-successful check model with no setup fees, making it accessible for businesses of all sizes.

Didit empowers you to build secure, scalable, and reliable identity verification flows, allowing your Kotlin microservices to focus on core business logic while trusting Didit for the heavy lifting of identity assurance.

Ready to Get Started?

Ready to see Didit in action? Get a free demo today.

Start verifying identities for free with Didit's free tier.

Try it

Try this in the sandbox

Run the check this guide describes, free.

ID Verification

The product this post is about, taken from its topic. Run it free in the sandbox.

$0.15 per checkStart free

Author

Alejandro Rosas

Co-founder and CTO

Alejandro Rosas

Alejandro Rosas

Co-founder and CTO

About Didit

Questions

Blog questions

Who writes the Didit blog?
The Didit team. Guides reviewed by Alberto Rosas, co-founder and CEO, carry his byline. The rest are published as Didit.
Which topics does the blog cover?
Eight topics: ID verification, business verification (KYB), AML, sanctions and compliance, fraud prevention, transaction monitoring and crypto, country guides, agents and developers, and product updates.
Is the blog available in my language?
Yes, in 15 languages: English, Spanish, French, German, Brazilian and European Portuguese, Catalan, Russian, Arabic, Chinese, Japanese, Hindi, Indonesian, Korean and Swahili. Not every post is translated, so each language shows the posts it has.
Where do I find product updates?
In the changelog at /changelog/ and under the Product updates topic.
Are these posts legal advice?
No. Regulation posts explain rules; your legal team decides how they apply.
How do I find posts on one topic?
Open one of the eight topics, or search the blog.
Are posts dated?
Yes. Every post shows when it was published and when it was last updated.
Do posts link to the docs?
Developer posts link to the matching page on docs.didit.me and to the API reference.
Is the blog the same as the docs?
No. The blog explains rules, markets and product changes for a general reader, while docs.didit.me holds the integration guides and the API reference. Developer posts link the matching docs page and the API reference they describe.

Compliance built in

Audited, certified and attested.

We hold the certifications and build each country's rules into your flows, so you can launch anywhere without worrying. Security and Compliance center

  • Regulation encoded into your flows

    Tell us what you do and where. Didit lists the rules that apply to you, with sources, and builds the checks each country needs into one workflow.

  • Ready for AMLR

    Every requirement of the new EU anti-money laundering rules, from checking customers to human review, is already covered by a Didit check.

  • Tested in Spain's Treasury sandbox

    Spain's Treasury published its supervised sandbox report on Didit's NFC plus active liveness onboarding; SEPBLAC took part and valued the added measures positively.

  • Audited, not self-declared

    iBeta Level 1 and Level 2. Liveness tested under ISO/IEC 30107-3.

Compliance assistant

Your obligations · 3 regions

EU · AMLRCustomer due diligence, human reviewCovered
Illinois, Texas, ColoradoExplicit biometric consentCovered
Germany · Youth protectionVerified adults only (JMStV)Covered
Workflow checked. Every obligation is met
  • SOC 2 Type 2
  • ISO 27001
  • iBeta Level 1 and Level 2
  • EU regulator attestation
  • FSM youth protection
  • GDPR
  • EBA remote onboarding
  • MiCA compatible
  • FIDO Alliance member
  • AMLREU AML Regulation ready

Integration · Didit MCP

Run Didit from your own AI agent

Connect Didit to Claude, Cursor, VS Code or ChatGPT and just ask in plain words. Your agent can do anything you can do in the console, with the same permissions you have.

Add to ClaudeChatGPT
Didit Academy · Lesson 04 · Use Didit with MCP
  • Build workflowsDescribe the checks you need. The agent creates and publishes the flow.
  • Run investigationsAsk why a session was declined, review cases, search people and companies.
  • Change rulesCreate payment rules, test them on past data and switch them on.
  • Pull reportsAsk for numbers, exports or the audit log.

Verify your first user today.

Start free

Free sandbox. Credit applies to work-email sign-ups.