You are developing a multiplayer gaming platform that stores player session data in Azure Cosmos DB using the SQL API and the .NET SDK v3. The Cosmos DB account is configured with Session consistency. The platform consists of two independent microservices running on separate server instances, each initializing its own CosmosClient instance.
Microservice A writes a new session document to the database. Immediately after, Microservice B must read that same session document to validate a lobby entry request. You must ensure that Microservice B reads the latest session state (read-your-writes guarantee) while maintaining the lowest possible read latency and avoiding hot partition issues under high write volume.
Which code segment should you implement to satisfy these requirements?
- Initialize containers with partition key path "/userId".
// Microservice A:
PlayerSession session = new PlayerSession { Id = "session_987", UserId = "user_123", IsActive = true };
ItemResponse<PlayerSession> writeResponse = await containerA.CreateItemAsync<PlayerSession>(
session,
new PartitionKey(session.UserId)
);
string token = writeResponse.Headers.Session;
// Microservice B:
ItemResponse<PlayerSession> readResponse = await containerB.ReadItemAsync<PlayerSession>(
session.Id,
new PartitionKey(session.UserId),
new ItemRequestOptions { SessionToken = token }
);Cevap - BInitialize containers with partition key path "/isActive".
// Microservice A:
PlayerSession session = new PlayerSession { Id = "session_987", UserId = "user_123", IsActive = true };
ItemResponse<PlayerSession> writeResponse = await containerA.CreateItemAsync<PlayerSession>(
session,
new PartitionKey(session.IsActive.ToString().ToLower())
);
string token = writeResponse.Headers.Session;
// Microservice B:
ItemResponse<PlayerSession> readResponse = await containerB.ReadItemAsync<PlayerSession>(
session.Id,
new PartitionKey(session.IsActive.ToString().ToLower()),
new ItemRequestOptions { SessionToken = token }
); - CInitialize containers with partition key path "/userId".
// Microservice A:
PlayerSession session = new PlayerSession { Id = "session_987", UserId = "user_123", IsActive = true };
await containerA.CreateItemAsync<PlayerSession>(
session,
new PartitionKey(session.UserId)
);
// Microservice B:
ItemResponse<PlayerSession> readResponse = await containerB.ReadItemAsync<PlayerSession>(
session.Id,
new PartitionKey(session.UserId)
); - DInitialize containers with partition key path "/userId".
// Microservice A:
PlayerSession session = new PlayerSession { Id = "session_987", UserId = "user_123", IsActive = true };
await containerA.CreateItemAsync<PlayerSession>(
session,
new PartitionKey(session.UserId)
);
// Microservice B:
ItemResponse<PlayerSession> readResponse = await containerB.ReadItemAsync<PlayerSession>(
session.Id,
new PartitionKey(session.UserId),
new ItemRequestOptions { SessionToken = session.UserId }
);