Skip to main content
Didit Raises $7.5M to Build the Infrastructure for Identity and Fraud
Didit
Back to blog
Blog · March 14, 2026

Building a Sanctions Screening Microservice with Go & Kafka

Discover how to design and implement a robust sanctions screening microservice architecture using Go, Kafka, and Open Policy Agent (OPA). This technical guide covers real-time AML compliance, API design, data synchronization.

By DiditUpdated
sanctions-screening-microservice-architecture.png

Scalable ComplianceImplement a sanctions screening microservice for real-time AML compliance, capable of handling high throughput and dynamic regulatory changes.

Event-Driven DesignLeverage Kafka for asynchronous processing and efficient data synchronization, ensuring minimal impact on core business logic.

Compliance-as-CodeUtilize Open Policy Agent (OPA) to externalize and manage compliance rules, enabling agile updates and auditability.

Enhanced Fraud DetectionIntegrate advanced risk signals and real-time data lookups to bolster your AML framework and improve fraud prevention.

In today's rapidly evolving regulatory landscape, financial institutions and regulated businesses face immense pressure to perform robust anti-money laundering (AML) checks, including comprehensive sanctions screening. Traditional monolithic systems often struggle to keep pace with dynamic regulations, real-time transaction volumes, and the need for agile updates. This blog post delves into building a modern, scalable sanctions screening microservice architecture using cutting-edge technologies like Go, Kafka, and Open Policy Agent (OPA).

The Need for Real-Time Sanctions Screening and Microservices

The global fight against financial crime demands vigilance. Regulators worldwide impose strict requirements for screening individuals and entities against sanctions lists (e.g., OFAC, UN, EU). Delays or failures can result in massive fines, reputational damage, and even criminal charges. Manual processes or batch-oriented screening systems are no longer sufficient for businesses operating in real-time environments.

A microservice architecture addresses these challenges by:

  • Scalability: Independently scale the sanctions screening service based on demand, without affecting other parts of your system.
  • Agility: Deploy updates and new rules quickly, crucial for responding to fast-changing sanctions lists.
  • Resilience: Isolate failures; an issue in the screening service won't bring down your entire platform.
  • Technology Diversity: Choose the best tools for the job. Go is an excellent choice for high-performance, concurrent services.

Our goal is to build a service that can screen new users, transactions, and ongoing customer profiles in near real-time AML scenarios, providing immediate risk assessments without introducing significant latency to user-facing applications.

Architectural Overview: Go, Kafka, and OPA for Compliance

Here's a high-level view of our proposed sanctions screening microservice:

Sanctions Screening Microservice Architecture Diagram

  1. Ingestion Layer (Kafka Producer): Core services (e.g., user onboarding, transaction processing) publish events (e.g., user_created, transaction_initiated) to a Kafka topic.
  2. Sanctions Screening Service (Go Consumer): A Go microservice consumes these events from Kafka.
  3. Data Enrichment: The Go service enriches the incoming data with internal customer information or external data sources (e.g., IP analysis, device fingerprinting).
  4. Sanctions Data Store: A dedicated, frequently updated database (e.g., PostgreSQL, Redis) stores consolidated sanctions lists from various providers.
  5. Matching Engine: The Go service implements fuzzy matching algorithms to compare incoming entity names against sanctions lists.
  6. Policy Decision Point (OPA): For complex rule evaluation and compliance-as-code, the Go service queries an Open Policy Agent (OPA) instance. OPA evaluates Rego policies against the enriched data and matching results to make a final compliance decision (e.g., approve, flag_for_review, deny).
  7. Result Publication (Kafka Producer): The Go service publishes the screening results (e.g., sanctions_screened event with status and details) back to another Kafka topic.
  8. Alerting/Actioning: Downstream services consume these results to trigger actions like manual review, account blocking, or transaction holds.

Implementing the Sanctions Screening Logic with Go

Go's excellent concurrency model and performance make it ideal for building high-throughput microservices. Here's how key components would be implemented:

Kafka Consumer in Go

package main

import (
    "context"
    "log"
    "os"
    "os/signal"
    "syscall"

    "github.com/segmentio/kafka-go"
)

func main() {
    broker := "localhost:9092"
    topic := "onboarding_events"
    groupID := "sanctions_consumer_group"

    r := kafka.NewReader(kafka.ReaderConfig{
        Brokers:   []string{broker},
        Topic:     topic,
        GroupID:   groupID,
        MinBytes:  10e3, // 10KB
        MaxBytes:  10e6, // 10MB
        MaxWait:   1 * time.Second,
    })

    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()

    sigChan := make(chan os.Signal, 1)
    signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

    log.Println("Starting Kafka consumer...")

    go func() {
        for {
            m, err := r.ReadMessage(ctx)
            if err != nil {
                log.Printf("Error reading message: %v", err)
                break
            }
            log.Printf("Received message: %s from topic %s partition %d offset %d\n", string(m.Value), m.Topic, m.Partition, m.Offset)
            // Process the message for sanctions screening
            // ... call screening logic ...
            // Publish result to another Kafka topic
        }
    }()

    <-sigChan
    log.Println("Shutting down consumer...")
    if err := r.Close(); err != nil {
        log.Fatalf("Failed to close reader: %v", err)
    }
}

Sanctions Matching Logic

The Go service will implement fuzzy matching algorithms (e.g., Jaro-Winkler, Levenshtein distance) to compare names, aliases, and addresses from incoming events against the stored sanctions data. Thresholds and weighting can be configured. Integration with external sanctions data providers involves robust APIs and data synchronization pipelines to keep lists up-to-date.

Compliance-as-Code with Open Policy Agent (OPA)

OPA is a game-changer for managing complex compliance rules. Instead of hardcoding logic, you define policies in Rego, OPA's high-level declarative language. This provides:

  • Centralized Policy Management: All compliance rules live in one place.
  • Version Control: Policies can be versioned, reviewed, and deployed like code.
  • Auditability: OPA provides clear decision logs, showing exactly why a decision was made.
  • Flexibility: Easily adapt to new regulations without redeploying the core service.

Example Rego Policy for Sanctions Screening

Consider a simple policy to flag if a match score exceeds a threshold and the entity type is 'individual':

package sanctions.screening

default allow = false

allow {
    input.match_score < 0.85
}

flag_for_review {
    input.match_score >= 0.85
    input.match_score < 0.95
    input.entity_type == "individual"
}

deny {
    input.match_score >= 0.95
}

The Go service would make an HTTP POST request to the OPA agent with the relevant data (input), and OPA returns a JSON decision.

How Didit Helps with Sanctions Screening

Building a robust sanctions screening microservice from scratch is a significant undertaking, requiring expertise in data ingestion, matching algorithms, regulatory compliance, and scalable infrastructure. Didit provides a comprehensive, out-of-the-box solution that can significantly accelerate your time to market and reduce operational overhead.

Didit's platform offers:

  • Real-time AML Screening: Screen users against 1,300+ global watchlists including OFAC, UN, EU sanctions, PEP databases, adverse media, and criminal records.
  • Configurable Risk Engine: Utilize a two-score system (match score + risk score) with configurable weights and thresholds, similar to what you'd achieve with OPA, but fully managed.
  • Ongoing AML Monitoring: Automatically re-screen verified users daily and receive webhook alerts on new sanctions hits or risk profile changes.
  • Unified Identity Platform: Combine sanctions screening with ID verification, biometrics, and fraud detection through a single API, streamlining your entire compliance and security workflow.
  • API-First Design: Easily integrate Didit's modules into your existing microservice architecture, allowing you to focus on your core business logic while offloading complex compliance tasks.
  • Cost-Effective: Didit offers transparent, pay-per-check pricing, often significantly more cost-effective than building and maintaining these systems in-house.

By leveraging Didit, you can quickly implement advanced sanctions screening capabilities, ensuring real-time AML compliance without the heavy development burden.

FAQ

What is sanctions screening in AML?

Sanctions screening in AML (Anti-Money Laundering) is the process of checking individuals, entities, and transactions against official government-issued lists of sanctioned parties. These lists contain individuals, organizations, and countries subject to financial restrictions due to their involvement in terrorism, drug trafficking, human rights violations, or other illegal activities. The goal is to prevent financial crime and ensure compliance with international regulations.

Why use microservices for sanctions screening?

Microservices enhance sanctions screening by providing scalability, agility, and resilience. They allow independent scaling of the screening component, rapid deployment of new rules, and isolation of failures, making it easier to adapt to evolving regulations and handle high transaction volumes efficiently. This enables real-time AML compliance crucial for modern businesses.

What is Compliance-as-Code?

Compliance-as-Code is an approach where regulatory and organizational policies are defined, managed, and enforced using code. Tools like Open Policy Agent (OPA) allow compliance rules to be written in a high-level language (Rego), version-controlled, and automatically applied, ensuring consistency, auditability, and faster adaptation to regulatory changes.

How does Kafka improve real-time AML screening?

Kafka improves real-time AML screening by providing a highly scalable and fault-tolerant event streaming platform. It enables asynchronous processing of customer and transaction data, decoupling the screening service from upstream systems. This ensures that screening can occur continuously and efficiently, without blocking core business operations, and allows for immediate action on suspicious activities.

Ready to Get Started?

Implementing a robust sanctions screening solution is critical for maintaining compliance and preventing financial crime. Whether you choose to build it yourself with a microservice architecture or leverage a powerful platform like Didit, prioritizing real-time capabilities and agile policy management is key.

Explore Didit's identity platform and see how our comprehensive AML screening and compliance tools can streamline your operations and secure your business.

Infrastructure for identity and fraud.

One API for KYC, KYB, Transaction Monitoring, and Wallet Screening. Integrate in 5 minutes.

Ask an AI to summarise this page
Sanctions Screening Microservice: Go, Kafka, OPA.