# hgs-study/distributed-lock-practice architecture

> Architecture diagram of the GitHub repository hgs-study/distributed-lock-practice, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hgs-study/distributed-lock-practice
- Repository: https://github.com/hgs-study/distributed-lock-practice

## Overview

Project Type: This is a specialized backend application demonstrating distributed locking mechanisms using Redis and Redisson in a Spring Boot environment.

##### Main Components

a. Application Layer:
- Spring Boot Application Container
- Stock Service Component
- Stock Domain Component
- Configuration Components (Redis Config)

b. Infrastructure Layer:
- Redis Server (for distributed locking)
- Database (for stock persistence)

##### Key Relationships to Highlight

a. Client Interaction Flow:
- Multiple Client Requests (100 threads as mentioned in README)
- Connection to Application Layer

b. Locking Mechanism:
- Redisson Client → Redis Server
- Lock Acquisition/Release Flow

##### Detailed Flow Representation

1. Multiple clients attempting stock purchase
2. Requests going through StockService
3. Redisson distributed lock acquisition
4. Stock update operation
5. Lock release

##### Important Architectural Aspects to Emphasize

a. Concurrent Access Handling:
- How multiple threads (100 as per test) interact
- Demonstrate lock queuing mechanism

b. Lock Management:
- Redisson lock acquisition flow
- Lock timeout and retry mechanism

##### Technical Details

- Spring Boot Application
- Redisson Client Configuration
- Redis Connection Properties
- Stock Entity Structure

##### Additional Notes

- Notes about concurrent access patterns
- Critical sections protected by distributed locks
- Success/failure scenarios

##### The role of Redis in maintaining distributed lock consistency

Remember to:
- Use consistent notation
- Version information
- Relevant metrics or performance indicators
- Document any assumptions or limitations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Clients
        C1((Client 1))
        C2((Client 2))
        C3((...))
        C4((Client 100))
    end

    subgraph "Spring Boot Application"
        APP["Application Container"]:::app
        SSERV["Stock Service"]:::service
        SDOM["Stock Domain"]:::domain
        RCONF["Redis Config"]:::config
        RPROP["Redis Properties"]:::config
        SPROP["Stock Properties"]:::config
        ACONF["Application Config"]:::config
    end

    subgraph Infrastructure
        REDIS[(Redis Server)]:::db
        DB[(Database)]:::db
    end

    subgraph "Test Layer"
        TEST["Stock Service Test"]:::test
    end

    %% Relationships
    C1 & C2 & C3 & C4 --> SSERV
    SSERV --> SDOM
    SDOM --> DB
    SSERV --> REDIS
    APP --> SSERV
    RCONF --> REDIS
    RPROP --> RCONF
    SPROP --> SSERV
    ACONF --> APP
    TEST --> SSERV

    %% Click Events
    click APP "https://github.com/hgs-study/distributed-lock-practice/blob/master/src/main/java/com/distributedlockpractice/DistributedLockPracticeApplication.java"
    click SSERV "https://github.com/hgs-study/distributed-lock-practice/blob/master/src/main/java/com/distributedlockpractice/service/StockService.java"
    click SDOM "https://github.com/hgs-study/distributed-lock-practice/blob/master/src/main/java/com/distributedlockpractice/domain/Stock.java"
    click RCONF "https://github.com/hgs-study/distributed-lock-practice/blob/master/src/main/java/com/distributedlockpractice/config/RedissonConfig.java"
    click RPROP "https://github.com/hgs-study/distributed-lock-practice/blob/master/src/main/java/com/distributedlockpractice/property/RedisProperty.java"
    click SPROP "https://github.com/hgs-study/distributed-lock-practice/blob/master/src/main/java/com/distributedlockpractice/property/StockProperty.java"
    click ACONF "https://github.com/hgs-study/distributed-lock-practice/blob/master/src/main/resources/application.yml"
    click TEST "https://github.com/hgs-study/distributed-lock-practice/blob/master/src/test/java/com/distributedlockpractice/service/StockServiceTest.java"

    %% Styles
    classDef app fill:#b3e0ff,stroke:#333,stroke-width:2px
    classDef service fill:#99ff99,stroke:#333,stroke-width:2px
    classDef domain fill:#ffb366,stroke:#333,stroke-width:2px
    classDef config fill:#ff99cc,stroke:#333,stroke-width:2px
    classDef db fill:#cc99ff,stroke:#333,stroke-width:2px
    classDef test fill:#ffff99,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Application"]:::app
        L2["Service"]:::service
        L3["Domain"]:::domain
        L4["Configuration"]:::config
        L5["Database"]:::db
        L6["Test"]:::test
    end
```
