Content Moderation Reference Architecture
Not everyone behaves appropriately while they are playing online, and some moderation is needed to maintain a civil, welcoming, and pleasurable experience amongst the players. By detecting inappropriate messaging content generated by the community and pruning or deleting it before it is shown to the public view, you can help achieve this goal.
This article will describe the architecture used in this sample on GitHub. Keep in mind that the code from this reference architecture is only an example for guidance and there may be places to optimize the code before using in a production environment.
Architecture Diagram
Architecture Services
- Azure AI Content Moderator - Checks text, image, and video content for material that is potentially offensive, risky, or otherwise undesirable. When such material is found, the service applies appropriate labels (flags) to the content.
- Azure Traffic Manager - When scaling across multiple regions globally, this service selects the closest region to connect to via DNS.
- Event Hub - A service tailored for real-time receiving and processing of a large number of events (chat strings in this case), in order, with little configuration or management overhead.
- Azure Function - Serverless compute service to run code on-demand -- in this case, code that invokes the different Azure AI services.
Architecture considerations
You only need to create a single Event Hub namespace that will contain the 2 Event Hubs used for sending and receiving messages, respectively.
The Azure AI Content Moderator detects profanity (masked or not) and PII. It supports several content types: text, images and videos. Text is the only content type covered in this architecture.
Deployment template
Click the following button to deploy the project to your Azure subscription:
This operation will trigger a template deployment of the azuredeploy.json ARM template file to your Azure subscription, which will create the necessary Azure resources. This may induce charges in your Azure account.
Have a look at the general guidelines documentation that includes a section summarizing the naming rules and restrictions for Azure services.
Note
If you're interested in how the ARM template works, review the Azure Resource Manager template documentation from each of the different services leveraged in this reference architecture:
There are two types of Azure AI services subscriptions. The first is a subscription to a single service, such as Azure AI Vision or the Azure AI Speech. A single-service subscription is restricted to just that service. The second type is a multi-service subscription. This allows you to use a single subscription for multiple Azure AI services. This option also consolidates billing. To make this reference architecture as modular as possible, the Azure AI services are each setup as a single service.
Finally, add these Function application settings so the sample project can connect to the Azure services:
- EVENTHUB_CONNECTION_STRING = The connection string to the Azure Event Hub namespace that was created
- CONTENTMODERATOR_KEY - The access key used to access the Azure AI Content Moderator resource that was created
Tip
To run the Azure Functions locally, update the local.settings.json file with these same app settings.
Step by Step
- The player's device opens a persistent and encrypted connection to the chat server in a specific region determined by Azure Traffic Manager. The chat server creates a process responsible for maintaining connectivity with the player along with some basic metadata.
- The player's client sends a chat message to the chat server over the secure connection previously created. The player's process in the chat server receives the message, decrypts it, and parses it.
- Standard validations are run, and the chat server calls the Azure Event Hub service, as it keeps the message order.
- The Azure Event Hub serves as an input trigger for an Azure Function.
- The Azure Function invokes the Azure AI Content Moderator service, that reviews the message sent by the player and returns a result.
- Another Azure Event Hub is set as the output for the Azure Function.
- The chat server receives the message from the Azure Event Hub.
- Optionally the chat server saves both the original message and the outcome from the Azure AI Content Moderator service in persistent storage like Azure Data Lake Storage.
- If the message was stored, it can be optionally saved into Azure Data Lake Analytics for analysis purposes.
- The result from the Azure AI Content Moderator service is then sent to the recipient player's process in the chat server. The process runs further validations on the message, serializes it and sends it to the recipient player's devices over their secure connection.
Azure Event Hubs
See this quickstart for a simple implementation for sending an event to an Event Hub in multiple programming languages. Some additional samples are available here.
Function triggered by an Azure Event Hub to another Azure Event Hub
When an Event Hubs trigger Function is triggered, the message that triggers it is passed into the Function as a string. Use the Event Hubs output binding to write events to an event stream.
[return: EventHub("ehigce-output", Connection = "EventHubConnectionAppSetting")]
public static string Run([EventHubTrigger("ehigce-input", Connection = "EventHubConnectionAppSetting")] string chatString, ILogger log)
Check out the common causes and solutions for 401 Access Denied errors when calling Azure AI services.
Security considerations
Do not hard-code any Event Hub or Azure AI services connection strings into the source of the Function. Instead, at a minimum, leverage the Function App Settings or, for even stronger security, use Key Vault instead. There is a tutorial explaining how to create a Key Vault, how to use a managed service identity with a Function and finally how to read the secret stored in Key Vault from a Function.
Review the Event Hub authentication and security model overview and put it into practice to ensure only your chat server can talk to the Event Hub.
Scaling
There are two points that could become a bottleneck in this architecture that you should plan for:
- Azure AI services scale well but they are throttled by default. Reach out to Azure support if you are planning to make use of them in large scale to increase capacity.
- The chat server receiving the Azure Event Hub responses will need to scale. Spin up enough virtual machines to address the demand.
Alternatives
You could consider leveraging Azure Cache for Redis and Azure Databricks if you are interested in gathering analytics using an Apache Spark-based platform.
Pricing
If you don't have an Azure subscription, create a free account to get started with 12 months of free services. You're not charged for services included for free with Azure free account, unless you exceed the limits of these services. Learn how to check usage through the Azure Portal or through the usage file.
You are responsible for the cost of the Azure services used while running these reference architectures. The total amount will vary based on usage. See the pricing webpages for each of the services that were used in the reference architecture:
You can also use the Azure pricing calculator to configure and estimate the costs for the Azure services that you are planning to use.
Feedback
Submit and view feedback for
