Scrivio Interview library

Distributed data and consistency

27 questions in 5 subtopics.

Eventual consistency

ConceptFoundations7 min read
An order service writes an order and publishes an OrderCreated event; a customer-facing order history service builds its own read model from those events. A user places an order and immediately refreshes the history page but does not see it. Explain what eventual consistency means here and why this is expected behaviour.
DebuggingFoundations7 min read
A Spring Boot service consumes Kafka events to update a projection table. Occasionally a customer's status in the projection goes from ACTIVE back to PENDING even though the source system shows ACTIVE. What are the likely causes and how would you fix them?
ScenarioIntermediate7 min read
Two microservices, Billing and Accounts, each own their data. A support engineer reports that for some customers the plan shown in Billing differs from Accounts for hours. Both services exchange events over a broker. How would you investigate and what design changes would you make so the divergence is bounded and detectable?
DesignIntermediate6 min read
You are designing a profile service where writes go to a primary PostgreSQL database and reads are served from read replicas with up to two seconds of replication lag. Product requires that a user always sees their own edits immediately. How would you implement read-your-writes in a Spring Boot service?
LeadershipAdvanced6 min read
Your organisation has 60 services and teams keep debating case by case whether a given cross-service read must be strongly consistent. As the architect responsible for consistency strategy, how would you set guidance that teams can apply without escalating every decision?
LeadershipPrincipal5 min read
The company is choosing between keeping a single large relational database shared by many teams and moving to database-per-service with eventual consistency between them. As the senior technical leader, how do you frame this decision for the executive team over a five-year horizon?

Distributed transactions and 2PC

ConceptFoundations6 min read
Explain how two-phase commit works and why a Spring Boot microservice that calls another service over HTTP cannot simply include that call inside its @Transactional method to get atomicity.
InternalsIntermediate6 min read
In a Spring Boot service, a method annotated with @Transactional saves an entity with JPA and sends a Kafka message with a KafkaTemplate. Describe what happens when the database commit fails after the send, and how Spring's Kafka transaction support and the outbox pattern change this.
ScenarioIntermediate7 min read
A legacy Java EE application uses JTA with XA transactions spanning an Oracle database and an IBM MQ queue. You are moving it to Spring Boot on Kubernetes. Would you keep XA, and what are the alternatives?
LeadershipAdvanced6 min read
Several teams in your organisation have independently introduced distributed transaction managers, custom outbox relays and ad hoc retry tables. You are asked to set a cross-team standard for atomic state change plus event publication. What would you standardise and how would you roll it out?
LeadershipPrincipal7 min read
A vendor proposes a distributed SQL database that offers serializable transactions across regions and claims it removes the need for sagas and outboxes across your services. How do you evaluate this claim as the technology leader?

Sagas

ConceptFoundations6 min read
Explain the difference between a choreographed saga and an orchestrated saga for an order flow that reserves stock, charges a card and schedules shipping.
DebuggingFoundations6 min read
In an order saga, the payment service refunded a customer twice when the order service retried a CancelPayment command after a timeout. Explain the cause and the fix.
DebuggingIntermediate6 min read
In a choreographed order saga, some orders stay in PAYMENT_PENDING forever. Payments and Orders communicate through Kafka topics. Walk through how you would find the cause.
DesignIntermediate7 min read
Design an orchestrated saga in Spring Boot for a travel booking that reserves a flight, a hotel and a car through three separate services. Cover the state model, persistence, retries, compensation and what happens when the orchestrator crashes mid-flow.
DesignAdvanced6 min read
Across your organisation, eight business processes span three to six services each and are implemented as choreographed sagas. Teams report that nobody can see the end-to-end flow, and changes break other teams. What would you propose?
LeadershipPrincipal6 min read
Your company is deciding whether to buy a commercial workflow orchestration platform or keep building sagas in each service. As the senior technical leader, what factors drive the decision and how would you structure it?

Idempotency keys

ConceptFoundations6 min read
A Kafka consumer in a Spring Boot service uses the default at-least-once delivery. Explain why messages can be processed twice and how an idempotent consumer prevents duplicate side effects.
CodingFoundations7 min read
Implement idempotent handling for a POST /payments endpoint in Spring Boot that accepts an Idempotency-Key header, so that a client retry after a timeout does not charge twice. Describe the table and the code flow.
DesignIntermediate7 min read
Your payment gateway integration calls an external provider that supports idempotency keys. Your own service also receives client retries and runs on 12 pods. Design end-to-end idempotency from client to provider, including how keys are generated and stored and how you handle partial failures.
LeadershipAdvanced6 min read
Incident reviews across your teams show repeated duplicate-processing bugs: double emails, double refunds and duplicated ledger entries. How would you address idempotency as an organisation-wide standard?
LeadershipPrincipal6 min read
Your company is exposing a public payments API to partners. As the senior technical leader, what long-term commitments about retries and idempotency would you make in the API contract, and what are the risks of getting them wrong?

Consistency in caches

ConceptFoundations6 min read
Explain cache-aside, read-through and write-through caching, and which consistency problems each one has in a Spring Boot service using Redis.
DebuggingFoundations7 min read
A Spring Boot service uses @Cacheable on getProduct(id) with Redis and @CacheEvict on updateProduct. After updates, users sometimes still see the old price for minutes. Both methods are @Transactional. What could cause this?
DesignIntermediate7 min read
Your service uses a two-level cache: Caffeine on each of 20 pods and Redis shared. Product data changes a few hundred times per minute and must not be stale for more than 5 seconds. Design the invalidation strategy.
ScenarioAdvanced7 min read
After a regional failover, several services served stale account limits from their caches for 30 minutes, leading to over-limit transactions. You are leading the follow-up across teams. What would you change?
LeadershipPrincipal6 min read
Your organisation spends heavily on a fleet of Redis clusters used by hundreds of services, and cache-related incidents are frequent. As the senior technical leader, how would you decide the long-term caching strategy?