How hrs05/key-value-store-v2 works
Project Type and Purpose
• This is a modular, full-stack key-value store application built with core Java, Spring Boot, gRPC, and REST.
• The “key.value” module implements the server side (in-memory store, TTL eviction, APIs), “common” holds shared Protocol Buffer definitions, and “client” provides a Java SDK (gRPC and REST) for consumers.
File-Structure Analysis
• Top-level pom.xml orchestrates three submodules: common, key.value, and client.
• common/src/main/proto/common.proto: shared message definitions.
• key.value/src/main/java/com/hrs/key/value: Spring Boot application, API packages (HandlerAPI, MasterAPI), data layer (KeyValueDataHandler, KeyValueDataMaster), handler layer, DTOs, TTL scheduler, configuration beans.
• client/src/main/java/com/proto/client: Spring Boot–based SDK, gRPC stubs, exception handling, service wrapper.
• asset/kv2ttl.jpg shows a TTL eviction sequence.
README Insights
• Version 2 adds: virtual threads (Java 21), Spring Boot integration, gRPC SDK, REST API support, pure-Java in-memory store, SAAS-style best practices.
Main Components
a. Client Application
• Java application using Client SDK
• Exposes high-level KeyValueApi calls
b. Client SDK (“client” module)
• gRPC stub + REST template
• KeyValueClientService
c. Network/API Layer on Server
• gRPC server endpoints (HandlerAPI, MasterAPI)
• REST controllers (mapped in Spring Boot)
d. Core Service Layer
• KeyValueService implementing business logic
e. Data Layer
• KeyValueDataHandler (per-key operations)
• KeyValueDataMaster (coordination, concurrency)
• In-memory data store (e.g., ConcurrentHashMap)
f. TTL Scheduler
• TTLScheduler (virtual threads scheduling eviction)
g. Shared Definitions
• common.proto messages and service definitions
Relationships & Interactions
• Client → (gRPC / HTTP) → Server API Layer → Service Layer → Data Layer → In-Memory Store
• TTL Scheduler → In-Memory Store (trigger expire/delete)
• common.proto binds client and server message formats
Architectural Patterns & Technologies
• Layered architecture (API → Service → Data)
• Spring Boot for auto-configuration, dependency injection
• Virtual threads (JDK 21) for high-concurrency scheduling
• gRPC for binary RPC, REST for HTTP compatibility
• Maven multi-module for code reuse (common, client, server)