Cosmos Gremlin

Description

Azure Cosmos DB Gremlin can be used as the backing implementation for Flex graph operations. Your application code should depend on IFlexGraphStore, while Flex provides the Cosmos Gremlin implementation and wiring.

Important concepts

  • IFlexGraphStore is the contract: your code uses a shared store abstraction.

  • Gremlin vs. model operations: generated templates typically show model-oriented operations (create node / get by id). Provider-specific traversal helpers may exist, but start with the shared operations first.

  • Partitioning matters: Cosmos performance depends heavily on partition key selection.

Configuration in DI

Add the provider in your DI composition root (commonly in EndPoints/...CommonConfigs/OtherApplicationServicesConfig.cs).

public static class OtherApplicationServicesConfig
{
		public static IServiceCollection AddOtherApplicationServices(
				this IServiceCollection services,
				IConfiguration configuration)
		{
				// Registers Cosmos Gremlin as the IFlexGraphStore bridge.
				// Flex auto-wires generated Queries/Handlers that use IFlexGraphStore.
				services.AddFlexCosmosGremlinGraphStore(configuration);

				return services;
		}
}

appsettings.json

Configuration is read from FlexBase:DataStores:Graph:CosmosGremlin.

Examples (template-based)

These examples mirror the generated Query and PostBusHandler templates. You do not register these types manually—Flex discovers and wires generated Queries/Handlers automatically.

Create node (PostBusHandler)

Get node by ID (Query)

Library-specific considerations

  • Primary key: PrimaryKey should be treated like a secret; store it securely.

  • Partition key: keep PartitionKey stable once data is written; changing it later is typically a migration.

  • Networking: Cosmos Gremlin is commonly locked down with firewall/VNet rules—ensure your app host can reach Hostname:Port.

Last updated