Coder Social home page Coder Social logo

spring-scalable-example's Introduction

spring-scalable-example

Application Level에서 대규모 트래픽 감당 예제

사용기술

  • Spring Cloud Gateway
  • Ribbon (Client Side LoadBalance)
  • Spring WebFlux, Reactor
  • RabbitMQ
  • Redis
  • Docker

실행 방법

$ git clone https://github.com/viviennes7/spring-scalable-example.git
$ cd spring-scalable-example
$ mvn clean install
$ docker-compose up

요구사항

  • 대규모 트래픽 가정
  • 제한된 수의 상품을 팜
  • 실패했던 성공했던 구매에 시도한 사람의 기록을 남겨야함

주의 사항

  • Race condition (제한된 개수만큼만 판매)
  • 대용량 트래픽에 대응하고, 정보를 남겨야함

ex) 맥북프로 최상위 옵션을 100만원에 100대만 판매. 들어올 트래픽은 10만으로 짐작됨.

HTTP API

  • Event 상품 구매
POST http://localhost:10000/service/events
  • Event 상품 구매 내역 조회
GET http://localhost:10000/service/orders

핵심로직

public Mono<Boolean> apply(Long userId) {
    return this.reactiveValueOperations.get(EVENT_APPLY_KEY)
            .doOnNext(size -> this.rabbitTemplate.convertAndSend(MicroserviceApplication.EVENT_TOPIC, "foo.bar.baz", userId))
            .filter(this::isPurchase)
            .flatMap(s -> this.reactiveValueOperations.increment(EVENT_APPLY_KEY))
            .flatMap(s -> this.reactiveListOperations.leftPush(EVENT_APPLY_LIST, userId.toString()))
            .map(add -> true)
            .defaultIfEmpty(false);
}

spring-scalable-example's People

Contributors

viviennes7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

d-e-f-e-a-t

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.