분류 전체보기
-
쿠폰 발급 요청 시, 확인하는 쿠폰 정보를 Redis Cache에 담아 개선하기SpringBoot 2024. 3. 19. 23:48
들어가며 선착순 쿠폰 발급 기능 개발을 진행하고 있는데, 현재 쿠폰 발급 요청에 대한 서비스 로직에 쿠폰 발급 전에 확인하는 것 중 하나인 해당 쿠폰의 유효성 검증 부분에 개선점이 필요했습니다. Coupon coupon = couponIssueService.findCoupon(couponId); 클라이언트에서 쿠폰 발급 요청 API를 호출할 때마다, 위와 같은 방식으로 데이터베이스에 있는 couponId에 대한 쿠폰 정보를 가져와서, 쿠폰의 유효성 검증을 수행했습니다. 여기서 유효성 검증은 사용자가 쿠폰 발급을 요청한 해당 쿠폰이 발급 가능 기간에 속하는지 검증하는 단계라고 보면 됩니다. 하지만 이러한 방식은 사용자가 요청할 때마다, 데이터베이스에서 값을 조회하기 때문에 순식간에 많은 사용자가 쿠폰 발급..
-
[LeetCode Hard] 262. Trips and UsersSQL 문제 풀이 2024. 2. 28. 12:46
테이블 정보 문제 The cancellation rate is computed by dividing the number of canceled (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day. Write a solution to find the cancellation rate of requests with unbanned users (both client and driver must not be banned) each day between "2013-10-01" and "2013-10-03". Round Cancellation Rate to two d..
-
Nginx에서 해외 IP 차단 설정하기Nginx 2024. 2. 24. 01:18
문제 갑자기 개발 서버 인스턴스의 CPU 사용률이 말도 안되게 높아졌다. 원래 왼쪽이 정상적인 사용률인데, 갑자기 오른쪽처럼 100%를 찍어버린 것이다. 인스턴스에 접속하여 top 명령어를 통해 확인해 보니, 프로세스를 실행한 커맨드를 의미하는 COMMAND에 java라고 써져있는 프로세스가 CPU 사용량이 90 ~ 100을 왔다 갔다하고 있었는데, 스프링부트쪽인거 같았다. 이런적이 한번도 없었는데 뭔가 느낌이 이상해서 nginx log를 살펴보니... 해외 IP에서 각종 취약점을 악용하여 우리쪽으로 API 요청을 보내고 있었고 대부분의 API 요청은 막혔지만, 어느 하나 걸려서 서버에 과부화가 걸린 것으로 파악된다. Nginx 해외 IP 차단 현재 서버는 해외 접속을 허용할 필요가 전혀 없기 때문에 해..
-
Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)Nginx 2024. 2. 24. 01:17
문제 백엔드 채팅 기능을 개발하면서 이미지와 파일 업로드를 추가했는데, 테스트를 해보니 오류가 발생하여 오류를 타고 타고 들어가다 nginx 로그를 확인해보니 제목과 같은 오류가 발생했다. 이는 nginx에서 client_max_body_size 설정 때문이고, 너무 큰 사이즈의 request를 보내지 못 하도록 제한을 거는 설정이다. client_max_body_size의 기본값은 1MB이다. request의 Content-Length 헤더 값이 이 설정된 값을 넘을 수 없기 때문에 파일 업로드할 때 오류가 발생한 것이다. 해결 악의적으로 큰 용량의 파일을 업로드해서 스토리지를 가득 채울 수 있기 때문에 우선은 채팅방에 업로드할 수 있는 최대 사이즈를 10MB로 설정하기로 하였다. 1. nginx 환경..
-
Redis 데이터 구조Redis 2024. 2. 20. 16:26
String String 타입의 데이터 구조, 텍스트, 직렬화된 객체 등을 저장하는 용도로 자주 사용됨. SET Time complexity: O(1) Description: 지정된 key의 저장된 문자열을 저장 SET key value GET Time complexity: O(1) Description: 지정된 key의 저장된 문자열을 조회 GET key SET, GET 실습 List 데이터 삽입 순서에 따라 정렬된 문자열 컬렉션의 형태 LRANGE Time complexity: O(S + N) - S는 (HEAD or TAIL)에서의 distance, N은 지정된 요소 수 Description: List에서 지정된 범위의 요소를 반환 LRANGE key start stop LPUSH Time comp..
-
[프로그래머스 Level 4] 자동차 대여 기록 별 대여 금액 구하기SQL 문제 풀이 2024. 2. 14. 17:07
테이블 정보 문제 CAR_RENTAL_COMPANY_CAR 테이블과 CAR_RENTAL_COMPANY_RENTAL_HISTORY 테이블과 CAR_RENTAL_COMPANY_DISCOUNT_PLAN 테이블에서 자동차 종류가 '트럭'인 자동차의 대여 기록에 대해서 대여 기록 별로 대여 금액(컬럼명: FEE)을 구하여 대여 기록 ID와 대여 금액 리스트를 출력하는 SQL문을 작성해주세요. 결과는 대여 금액을 기준으로 내림차순 정렬하고, 대여 금액이 같은 경우 대여 기록 ID를 기준으로 내림차순 정렬해주세요. 예시 주의 사항 FEE의 경우 예시처럼 정수부분만 출력되어야 합니다. 문제 풀이 1 (MySQL) 데이터 타입을 꼼꼼히 살펴보지 않으면 어떻게 되는지 느끼게 해준 문제이다. 아래 코드는 답은 맞았으나 문제..
-
[Kafka 개념] Kafka 브로커, 복제, ISR(In-Sync-Replica)Apache Kafka/개념 정리 2024. 2. 9. 17:46
Kafka Broker 카프카 브로커는 카프카가 설치되어 있는 서버 단위를 말한다. 보통 3개 이상의 브로커로 구성하여 사용하는 것을 권장한다. 만약 파티션이 1개이고, replication이 1인 topic이 존재하며 브로커가 3대라면, 브로커 3대 중 1대에 해당 토픽의 정보(데이터)가 저장된다. Kafka Replication replication은 partition의 복제를 뜻한다. 만약 replication이 1이라면, partition은 1개만 존재한다는 것이고 replication이 2라면, partition은 원본 1개와 복제본 1개로 총 2개가 존재한다. replication이 3이라면?? 그렇다! replication이 3이라면, partition은 원본 1개와 복제본 2개로 총 3개가..
-
[Spring Boot] 채팅방에서 사용자가 업로드한 파일을 NHN Cloud의 Object Storage를 통해 관리하기SpringBoot 2024. 2. 7. 01:53
파일 업로드, 삭제, 다운로드 코드 작성 아래 NHN Cloud API 가이드에서 목차를 보면, 오브젝트 부분에 업로드 / 다운로드 / 복사 / 삭제등에 대한 작성법이 자세히 나와있다. API 가이드 - NHN Cloud 사용자 가이드 Storage > Object Storage > API 가이드 사전 준비 오브젝트 스토리지 API를 사용하려면 먼저 인증 토큰(token)을 발급 받아야 합니다. 인증 토큰은 오브젝트 스토리지의 REST API를 사용할 때 필요한 인증 키 docs.nhncloud.com 가이드에서는 RestTemplate을 사용하여 설명해주고 있는데 나의 경우 아래 업로드와 삭제 부분 코드를 보다시피 해당 부분에 대해서는 WebClient 방식으로 작성하였다. 다만 다운로드 부분은 작성하..