← Fidelity Interview Insights

Fidelity·Backend Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Technical screen at Fidelity for a backend role, pretty deep on Spring Boot internals. The multi-datasource question was the centerpiece and they clearly wanted more than surface-level answers.

Questions Asked (3)

Q1

Walk me through how you'd configure two separate databases in a single Spring Boot application, including transaction management and repository scoping.

System DesignTechnical Trade-offsAPI & Integrations
Author's notes

This is the kind of question where you can start confidently and then slowly realize how many layers there are.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by outlining the high-level architecture: define two DataSource beans, two EntityManagerFactory beans, and two TransactionManager beans, each scoped to a specific package. Then explain how to use @Transactional with the correct transaction manager and how to configure repository scanning to avoid conflicts.

Pro tip: Emphasize that you must explicitly specify the transaction manager in @Transactional when multiple exist, and consider using a custom annotation to reduce boilerplate. Also mention that you should disable auto-configuration for DataSource to avoid conflicts.

1. Define multiple DataSources

Create separate DataSource beans for each database, using @ConfigurationProperties to bind properties from application.yml. Mark one as @Primary to resolve ambiguity.

2. Configure EntityManagerFactory and TransactionManager

For each DataSource, define a LocalContainerEntityManagerFactoryBean and a JpaTransactionManager, specifying the packages to scan for entities and repositories.

3. Scope repositories and entities

Use @EnableJpaRepositories with basePackages and entityManagerFactoryRef, and specify the transactionManagerRef. Place entities and repositories in separate packages to avoid overlap.

4. Manage transactions explicitly

When using @Transactional, specify the transaction manager bean name if not using the primary one. Consider creating custom annotations that combine @Transactional with the correct manager.

5. Handle cross-database transactions

Acknowledge that distributed transactions are complex; discuss options like ChainedTransactionManager (deprecated) or JTA, and recommend avoiding cross-database transactions by designing services to be database-specific.

Key Points to Mention

  • Use @Primary to designate a default DataSource, EntityManagerFactory, and TransactionManager.
  • Separate packages for entities and repositories to prevent scanning conflicts.
  • Explicitly reference the correct transaction manager in @Transactional or via custom annotations.
  • Disable DataSourceAutoConfiguration to prevent Spring Boot from auto-configuring a single DataSource.
  • Consider using multiple persistence units or Spring Data JPA's support for multiple modules.
  • Discuss trade-offs: complexity, potential for distributed transactions, and testing challenges.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

What are the common pitfalls when mixing JdbcTemplate and JPA across two datasources in the same application?

Technical Trade-offsSystem Design
Author's notes

Shorter answer than I expected them to want.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by acknowledging that mixing JdbcTemplate and JPA across two datasources is a valid pattern for performance or legacy reasons, but it introduces complexity. Then systematically outline the main pitfalls: transaction management, connection handling, entity state consistency, and configuration errors. Conclude with mitigation strategies to show depth.

Pro tip: Emphasize that the biggest risk is transaction propagation across datasources—JPA's EntityManager and JdbcTemplate won't share the same transaction unless explicitly coordinated, leading to partial commits. Mention that using a single transaction manager per datasource and avoiding cross-datasource transactions is often the pragmatic choice.

1. Clarify the setup

Briefly describe the scenario: two datasources, one accessed via JPA (with its own EntityManagerFactory and transaction manager) and the other via JdbcTemplate (with its own DataSource and transaction manager).

2. Identify transaction pitfalls

Discuss how transactions are managed separately, leading to issues like partial commits, inconsistent reads, and the need for distributed transactions (e.g., JTA) which add complexity.

3. Highlight connection and resource issues

Explain that each datasource has its own connection pool, and misconfiguration can cause connection leaks, exhaustion, or deadlocks, especially under high load.

4. Address entity state and caching

Point out that JPA's first-level cache and entity lifecycle are not aware of changes made via JdbcTemplate, leading to stale data and unexpected behavior.

5. Propose mitigation strategies

Suggest best practices: use a single datasource if possible, isolate operations, use separate transaction managers, avoid cross-datasource transactions, and consider JTA with XA if absolutely necessary.

Key Points to Mention

  • Transaction management: separate PlatformTransactionManager instances, no shared transaction context, risk of partial commits.
  • Connection pooling: each datasource has its own pool; misconfiguration can lead to resource exhaustion.
  • Entity state: JPA's persistence context not synchronized with JdbcTemplate updates, causing stale reads.
  • Configuration complexity: multiple EntityManagerFactory, DataSource, and transaction manager beans; risk of wiring errors.
  • Performance trade-offs: JdbcTemplate may be faster for bulk operations, but mixing can lead to inconsistent performance.
  • Testing and debugging: harder to trace issues across two different data access technologies.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

When would you actually need JTA or distributed transactions instead of just managing two separate transaction managers?

Technical Trade-offsSystem Design
Author's notes

Blanked for a second here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying that JTA is needed when a single atomic unit of work must span multiple transactional resources (e.g., two databases or a database and a message queue) with ACID guarantees. Then explain that if you can avoid distributed transactions through patterns like sagas or outbox, that's often preferable. Finally, discuss the trade-offs and when JTA is truly necessary.

Pro tip: Mention that many modern architectures avoid JTA by using eventual consistency and compensating transactions, but JTA remains relevant in legacy systems or when strict ACID across resources is non-negotiable, such as in financial applications.

1. Define the problem

Explain what a distributed transaction is: a single logical unit of work that spans multiple physical resources, requiring atomicity across them.

2. Identify when JTA is needed

List scenarios: when you must update two databases atomically, or a database and a message queue, and you cannot tolerate eventual consistency.

3. Compare with separate transaction managers

Discuss why managing two separate transaction managers fails: lack of atomicity, potential for partial commits, and complex error handling.

4. Discuss alternatives and trade-offs

Mention patterns like sagas, outbox, or eventual consistency that avoid JTA, and note that JTA adds complexity and performance overhead.

5. Conclude with a recommendation

State that JTA is necessary when strict ACID across resources is required and alternatives are not feasible, but prefer simpler patterns when possible.

Key Points to Mention

  • ACID properties and the need for atomicity across multiple resources
  • XA protocol and two-phase commit (2PC) as the underlying mechanism
  • Scenarios like financial transactions where partial commits are unacceptable
  • Limitations of JTA: performance overhead, complexity, and reduced availability
  • Alternative patterns: saga, outbox, event sourcing, and eventual consistency
  • The role of the transaction manager and resource managers in JTA

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.