Đang mở hậu trường...
You are building an e-commerce checkout service. When a user places an order, the system must: (1) save the order to the database, (2) charge the payment, and (3) send a confirmation email via a third-party email provider that occasionally takes 3-5 seconds to respond. The product team requires checkout to feel instant for the user. Given this constraint, what is the most appropriate way to handle the confirmation email step?
A senior engineer is asked in an interview: "Tell me about a time a technical decision you owned caused a production incident that affected multiple teams." The candidate must choose how to structure the answer. Which response best demonstrates senior-level ownership under the STAR framework?
In a Spring Boot service, a fresher writes the following code: @Service public class OrderService { public void processAll(List<Order> orders) { for (Order o : orders) { saveOne(o); // direct call to method in the same class } } @Transactional public void saveOne(Order o) { orderRepository.save(o); } } When processAll() is called from a controller and saveOne() throws a RuntimeException midway, the already-saved rows are NOT rolled back. What is the main reason?
Your team runs a product detail API backed by Redis with a 5-minute TTL per product key. Every evening when a flash sale starts, one very popular product's cache entry expires and within the same second thousands of concurrent requests all miss the cache and hit PostgreSQL, causing timeouts. The data may be a few seconds stale without harm. Which change best addresses this specific problem with the least complexity?
You are implementing a task scheduler that stores 1,000,000 task priorities in a binary min-heap backed by an array. The team now asks you to also report the task with the HIGHEST priority value (the maximum element), without changing the data structure. Assuming no extra bookkeeping is added, what is the worst-case time complexity of finding that maximum element?
A junior developer is asked in an interview: "Tell me about a time you made a mistake that affected your team." They have about 2 minutes to answer and the only real incident they can recall is a bad database migration they pushed that broke the staging environment for half a day. Using the STAR method under this time constraint, how should they structure the answer most effectively?
Your team maintains a shared counter updated by 32 worker threads on a 16-core server. The current implementation uses a mutex around `counter++`. A colleague proposes replacing it with a lock-free loop using an atomic compare-and-swap (CAS) on the counter, arguing it will 'eliminate blocking and always be faster'. Under sustained high contention from all 32 threads hammering the same cache line, what is the most accurate assessment of this trade-off?
Your platform serves a product catalog to 40 microservices. Today each service keeps its own in-process Caffeine cache (TTL 5 min) of catalog entities. After a pricing bug shipped bad data, it took 5 minutes for all nodes to converge, and finance demanded sub-second correctness for price changes. Traffic is read-heavy (99:1), p99 latency budget is 30ms, and the catalog service cannot absorb full read traffic if caches are removed. As the engineering lead, which architectural direction best balances correctness, latency, and organizational cost?
Your team is building a mobile app that calls three stateless backend services running behind a round-robin load balancer, with no shared session store (no Redis) in the budget. Users must stay logged in across requests that may hit any of the three instances. Which authentication approach best fits this constraint, and why?
Your team runs a reporting query on PostgreSQL inside a transaction set to READ COMMITTED. The query reads the `orders` table twice within the same transaction; between the two reads, another session commits an UPDATE to one of the rows being read. The second read returns a different value for that row. Which anomaly is this, and which isolation level is the lowest one that would prevent it?
In a Spring Boot service, a junior developer writes a method `processAll()` (no annotation) that loops over a list of orders and calls `this.saveOrder(order)`, where `saveOrder` is a public method in the same class annotated with `@Transactional`. In testing, a failure inside `saveOrder` does not roll back the row that was already written. Given the app uses Spring's default proxy-based AOP, what is the most accurate explanation and fix?
Two threads in a banking app each need to lock both `accountA` and `accountB` to transfer money. Thread 1 does `lock(accountA); lock(accountB);` while Thread 2 does `lock(accountB); lock(accountA);`. Occasionally the program freezes with both threads stuck and no CPU usage. What is happening, and what is the simplest fix?
A junior developer creates a `User` class and overrides `equals()` to compare users by their `id` field, but forgets to override `hashCode()`. He then puts a `User` object into a `HashMap<User, String>` and later tries to look it up using a *different* `User` instance that has the same `id`. What is the most likely result?
Your team maintains a Python service that handles ~2000 concurrent client connections, each spending most of its time waiting on HTTP calls to downstream APIs, plus a short CPU-bound JSON signature check (~5ms) per request. The service currently uses a thread pool of 200 OS threads. A colleague proposes rewriting it on asyncio with a single event loop. What is the most accurate assessment of this trade-off?
You are building a stock-price dashboard. The browser clients only need to *receive* price updates pushed from the server (they never send data back over that channel), updates arrive every 1-2 seconds, and the app must run inside a corporate network where the proxy only reliably allows plain HTTP/HTTPS traffic. Which transport is the most appropriate choice?
Your team runs an online store on PostgreSQL. A report query reads the row for product #42 (price = 100), and a few milliseconds later, within the SAME transaction, reads that row again and now sees price = 120 because another transaction committed an update in between. The transaction is running at the READ COMMITTED isolation level. What is this anomaly called, and what is the lowest standard isolation level that would prevent it?
An order service must (1) persist a new order row in its PostgreSQL database and (2) publish an OrderCreated event so downstream inventory and notification services react. The team notices that after DB commit, the process sometimes crashes before the broker ack, so events are silently lost. They consider replacing the direct publish with the Transactional Outbox pattern (write the event into an outbox table in the same DB transaction, then a relay polls the table and publishes to Kafka). What is the most accurate trade-off of adopting this pattern here?
You are developing a Spring Boot application. Inside a Service class, a public method `processOrder()` calls another public method `logHistory()` within the same class. Both methods are marked with @Transactional. You notice that even if `logHistory()` contains logic meant to be transactional, that configuration is ignored. Why does this happen?
You are architecting a high-throughput caching service using java.util.HashMap, where the system keys are composite objects that must be updated frequently based on external events. If a developer uses a mutable object as a key and modifies its internal fields after the object has been inserted into the HashMap, what is the primary consequence observed during the object's lifecycle in production?
In an operating system, an application creates execution units to perform tasks concurrently. How does memory sharing differ between multiple threads within the same process compared to multiple independent processes?
A high-throughput analytics platform needs to handle frequent write spikes to aggregated metric counters. The engineering team is evaluating whether to implement a Write-Through or a Write-Behind (Write-Back) caching strategy. What is the primary architectural trade-off of choosing Write-Behind over Write-Through in this scenario?
Your organization is redesigning the global multi-region ingress and security architecture for an enterprise API platform. The security team mandates near real-time authorization revocation (under 5 seconds) across all regions, while platform metrics show that synchronous OAuth2 token introspection against the primary IdP region adds up to 200ms latency to regional requests and creates a cross-region single point of failure. Which architectural strategy best balances low latency, regional fault isolation, and the strict revocation mandate?
You are designing a leaderboard feature that processes a continuous stream of millions of player scores in real time. The system only needs to display the top 100 highest scores at any given moment and must operate with strictly minimal memory usage ($O(k)$ auxiliary space where $k = 100$). Which data structure and strategy best satisfies these constraints?
You are architecting a globally distributed e-commerce platform that employs a multi-region active-active replication strategy. To ensure low checkout latency, the read-heavy validation service performs queries against the nearest local replica. When a user updates their shopping cart and immediately triggers a checkout transaction, the system occasionally fails validation due to state inconsistency. Which distributed database phenomenon best explains the root cause of this failure mode?
In an e-commerce platform, when a customer places an order, the Order Service must notify the Notification Service to send an email and the Analytics Service to record the purchase. To minimize latency for the customer and prevent failures in downstream services from blocking the checkout response, which communication pattern should be used?
Two weeks before a critical product launch, your team discovers a non-blocking performance degradation under heavy load. The senior engineer wants to delay the release by two weeks to refactor the core data pipeline properly, while the Product Manager insists on launching on schedule with a temporary caching workaround and monitoring. As the mid-level engineer leading this feature, how should you evaluate the trade-offs and drive a resolution?
A Spring Boot platform requires failed order attempts to roll back all order changes while still committing an audit record. The current service calls its own `writeAudit()` method annotated with `@Transactional(propagation = REQUIRES_NEW)`, but the audit record is rolled back with the order transaction. What should the lead establish as the preferred platform-wide design?
A Java service stores customer records in a HashSet<Customer>. Two Customer objects with the same customerId must be treated as duplicates, but the set currently keeps both objects. What is the most appropriate fix?
In a high-throughput multi-threaded application, you replace a mutex-protected counter with a single `std::atomic<int64_t>` using `fetch_add`. While this initially improves throughput, the system experiences significant performance degradation on multi-socket servers under heavy contention, characterized by high CPU utilization despite low effective throughput. What is the physical mechanism causing this performance collapse, and what is the standard architectural mitigation for high-frequency write contention in this scenario?
An application uses an in-memory cache with a fixed capacity. When the cache becomes full, it should remove the item that has not been accessed for the longest time. Which eviction policy matches this requirement?