transaction-consistency-designer

작성자: kotlin

Kotlin + Spring 비즈니스 워크플로우를 위한 안전한 트랜잭션 경계, 롤백 동작, 멱등성, 잠금 및 일관성 전략을 설계합니다. 다음과 같은 경우에 사용하세요…

npx skills add https://github.com/kotlin/kotlin-backend-agent-skills --skill transaction-consistency-designer

Transaction Consistency Designer

Source mapping: Tier 1 critical skill derived from Kotlin_Spring_Developer_Pipeline.md (SK-09).

Mission

Place transaction boundaries where business invariants are actually enforced, not where annotations are easiest to type. Prevent data loss, duplicate side effects, and hidden consistency bugs.

Gather These Inputs

  • The business workflow step by step.
  • The repositories and tables touched by each step.
  • Current @Transactional annotations, propagation, isolation, and exception handling.
  • Any external HTTP, message broker, scheduler, or file I/O inside the workflow.
  • Idempotency, retry, and concurrency requirements.

Model The Workflow Explicitly

  • Break the use case into state-changing steps and side effects.
  • Mark which steps must be atomic together and which can be asynchronous.
  • Mark where external systems are called.
  • Mark where retries may happen.
  • Mark the business invariant that must not be violated.

Decision Rules

  • Keep one database transaction focused on one consistency boundary.
  • Avoid holding a database transaction open across external network calls.
  • Prefer idempotency keys plus unique constraints for duplicate-request safety.
  • Prefer the outbox pattern or post-commit publication for messages that must reflect committed state.
  • Choose locking strategy based on contention and correctness needs:
    • optimistic locking for low-contention update races
    • unique constraints for duplicate prevention
    • pessimistic locking only when contention and correctness justify it

Spring-Specific Checks

  • Verify whether @Transactional is on a proxied public entry point.
  • Verify whether self-invocation bypasses the transaction boundary.
  • Verify rollback rules. By default, unchecked exceptions roll back, checked exceptions may not.
  • Verify whether readOnly = true is used only where appropriate.
  • Verify whether REQUIRES_NEW is truly required or is masking a design issue.
  • Treat NESTED as database- and platform-dependent, not a universal escape hatch.

Anti-Patterns To Flag

  • @Transactional on controllers by default.
  • One transaction that does database writes and then performs slow HTTP calls.
  • Catching exceptions inside the transaction and converting them to success-like flows.
  • Publishing irreversible side effects before commit.
  • Assuming retries are safe without idempotency.
  • Using a bigger propagation setting to hide unclear boundaries.

Advanced Consistency Nuances

  • Distinguish duplicate prevention from concurrency control. A unique constraint solves one class of race, not lost updates or write skew.
  • Remember that many integrity failures surface on flush or commit, not at the line that changed the entity. Design tests and exception handling accordingly.
  • UnexpectedRollbackException often means an inner operation marked the transaction rollback-only even though the outer layer tried to return success.
  • Isolation levels are database-specific in effect. The same setting on Postgres, MySQL, and SQL Server may protect different anomalies.
  • Deadlock and serialization-failure retries belong at a carefully chosen outer boundary. Retrying a half-executed workflow with external side effects is dangerous.
  • @TransactionalEventListener and TransactionSynchronization are phase-sensitive. Choose before-commit, after-commit, or after-rollback behavior deliberately.
  • If the workflow crosses service boundaries, distinguish local transaction design from saga or orchestration design. Do not pretend one local transaction can guarantee distributed consistency.
  • In reactive or coroutine transaction flows, verify which transaction manager and context propagation model is actually in use. Imperative assumptions often fail there.

Expert Heuristics

  • Start from the invariant, not from the annotation. Ask what must never be observably false to users or downstream systems.
  • Prefer database-enforced invariants for uniqueness and impossible states, then use application logic to make violations rare and understandable.
  • If a workflow mixes command and query steps, decide whether read-your-write guarantees are required immediately or whether eventual consistency is acceptable.
  • If the team wants REQUIRES_NEW, ask whether they are isolating audit logging, masking rollback behavior, or compensating for a larger design problem.

Output Contract

Return these sections:

  • Consistency goal: the business invariant being protected.
  • Recommended boundary: where the main transaction starts and ends.
  • Propagation and isolation: only the settings that matter and why.
  • Idempotency and concurrency: duplicate handling, locking, and retry safety.
  • External side effects: what must happen outside the transaction or through outbox-style patterns.
  • Verification: tests or scenarios that prove rollback, duplicate handling, and conflict behavior.

Guardrails

  • Do not put @Transactional on every service method by default.
  • Do not recommend distributed 2PC or XA unless the project already uses it and truly requires it.
  • Do not ignore the cost of holding database connections during external calls.
  • Do not treat duplicate prevention as an application-only concern when the database can enforce it.

Quality Bar

A good run of this skill turns a vague workflow into explicit consistency boundaries and testable invariants. A bad run decorates methods with @Transactional without modeling failure paths, retries, and side effects.

kotlin의 다른 스킬

ci-cd-containerization-advisor
kotlin
재현 가능한 빌드, 이미지 및 배포 파이프라인을 설계합니다. Kotlin 및 Spring 애플리케이션을 대상으로 하며, CI 검증, 계층형 컨테이너, 롤아웃 안전성 등을 포함합니다.
official
configuration-properties-profiles-kotlin-safe
kotlin
Design and diagnose Spring configuration, profiles, and `@ConfigurationProperties` binding for Kotlin applications. Use when property binding fails,…
official
dependency-conflict-resolver
kotlin
Diagnose and resolve Gradle and Spring classpath conflicts, version drift, and binary incompatibilities in Kotlin applications. Use when `NoSuchMethodError`,…
official
domain-decomposition-api-design-advisor
kotlin
구현을 시작하기 전에 비즈니스 범위를 경계 컨텍스트, 모듈 또는 서비스 경계, 워크플로우, API 계약으로 분해합니다. 새로운 것을 설계할 때 사용하세요.
official
error-model-validation-architect
kotlin
Kotlin과 Spring 서비스를 위한 일관된 API 검증 및 오류 처리 동작을 설계하고 구현합니다. 오류 페이로드를 정의하거나 프레임워크를 매핑할 때 사용합니다.
official
gradle-kotlin-dsl-doctor
kotlin
Generate, debug, and repair Kotlin + Spring Gradle builds with minimal, compatible changes. Use when `build.gradle.kts` or `settings.gradle.kts` is failing,…
official
integration-resilience-engineer
kotlin
탄력적인 HTTP, 메시징, 예약 통합을 Kotlin 및 Spring 서비스용으로 설계하며 명시적인 타임아웃 예산, 재시도, 멱등성, 서킷 브레이커를 포함합니다.
official
jackson-kotlin-serialization-specialist
kotlin
Kotlin과 Jackson을 사용하는 Spring 애플리케이션에서 JSON 직렬화 및 역직렬화 동작을 진단하고 설계합니다. DTO 역직렬화 실패 시, 기본값…
official