wasAsked.

If we are sending an object for an API, how do you track the object.

HCA Healthcare · Role not specified · technical

Published

Year not specified · Software Engineering

Community answers

Posted by wasAsked editorial collection

"Tracking an object" can mean a few things in an interview; clarify and cover the relevant ones. 1. Tracking the request end to end (observability) - Each request gets a trace or correlation ID (W3C traceparent, Activity.TraceId in .NET) that flows through the API, downstream services and message queues. - Structured logs include the ID and key business identifiers (order ID), so you can search everything that happened to that object. - Return the ID to the client in a response header and in error responses, so a user or support team can reference it. - Distributed tracing (OpenTelemetry, Application Insights) shows each step and its timing. 2. Tracking the object's processing status (business tracking) For objects processed asynchronously (orders, payment requests, file uploads): - The API returns an identifier immediately (201 Created with Location, or 202 Accepted with a status URL). - The object has a status field in the database (Received, Processing, Completed, Failed) updated by each processing step. - Clients poll GET /api/orders/{id}/status, or receive updates through webhooks, SignalR or WebSockets. - Idempotency keys ensure that if the client resends the same object (retry), it is recognised as the same request instead of being created twice. 3. Tracking changes to the object (auditing and history) - Audit tables or event logs record who changed what and when (EF Core SaveChanges interceptors, temporal tables in SQL Server, or event sourcing). - Row versions (concurrency tokens or ETags) track versions and prevent lost updates when two users modify the same object. 4. Entity Framework change tracking (if the question is about EF) - When an object is sent to the API and loaded or attached to a DbContext, EF's change tracker records its original values and state (Added, Modified, Deleted, Unchanged), and SaveChanges generates SQL for the changes. - For disconnected objects from API requests, load the existing entity and apply changes, or attach and set the state explicitly; use AsNoTracking for read-only queries. Example summary: "When the client posts an order, we return an order ID and a trace ID. The order status is stored and updated as it moves through processing queues, every log carries the trace ID, changes are audited with a rowversion for concurrency, and the client tracks progress through a status endpoint and SignalR notifications."

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics