Q67. AWS SQS의 가시성 제한 시간을 활용한 메시지 중복 처리 방지

AWS 자격증을 준비하는 여러분, 안녕하세요. 오늘은 Amazon SQS(Simple Queue Service)를 사용할 때 발생할 수 있는 메시지 중복 처리 문제와 그 해결 방법에 대해 알아보겠습니다. 이는 실제 시스템 설계에서 자주 마주치는 문제이며, AWS 솔루션 아키텍트 자격증 시험에서도 중요하게 다루는 주제입니다.

문제 상황

Q67:
한 회사가 여러 Amazon EC2 인스턴스에서 애플리케이션을 호스팅하고 있습니다. 이 애플리케이션은 Amazon SQS 대기열의 메시지를 처리하고, Amazon RDS 테이블에 데이터를 쓴 후 대기열에서 메시지를 삭제합니다. 그런데 RDS 테이블에서 가끔 중복 레코드가 발견되고 있습니다. SQS 대기열에는 중복 메시지가 없는 것으로 확인되었습니다.

솔루션 설계자는 메시지가 한 번만 처리되도록 하기 위해 어떤 조치를 취해야 할까요?

<small>A company hosts an application on multiple Amazon EC2 instances. The application processes messages from an Amazon SQS queue, writes to an Amazon RDS table, and deletes the messages from the queue. Occasionally, duplicate records are found in the RDS table. There are no duplicate messages in the SQS queue.
What should a solutions architect do to ensure that messages are processed only once?</small>

선택지

A. CreateQueue API 호출을 사용하여 새 대기열을 만듭니다.
<small>Use a CreateQueue API call to create a new queue.</small>

B. AddPermission API 호출을 사용하여 적절한 권한을 추가합니다.
<small>Use an AddPermission API call to add appropriate permissions.</small>

C. ReceiveMessage API 호출을 사용하여 적절한 대기 시간을 설정합니다.
<small>Use a ReceiveMessage API call to set the appropriate wait time.</small>

D. ChangeMessageVisibility API 호출을 사용하여 가시성 시간 초과를 늘립니다.
<small>Use a ChangeMessageVisibility API call to increase the visibility timeout.</small>

정답 및 해설

정답은 D입니다.

Amazon SQS의 가시성 제한 시간(Visibility Timeout)은 메시지 중복 처리를 방지하는 핵심 메커니즘입니다. 가시성 제한 시간은 SQS가 메시지를 반환할 때 시작되며, 이 기간 동안 다른 소비자는 해당 메시지를 볼 수 없습니다. 소비자는 이 시간 내에 메시지를 처리하고 삭제해야 합니다.

만약 소비자가 가시성 제한 시간 내에 메시지 처리를 완료하지 못하면, 해당 메시지는 다시 대기열에 표시되어 다른 소비자에 의해 처리될 수 있습니다. 이로 인해 중복 처리가 발생할 수 있습니다.

ChangeMessageVisibility API를 사용하여 가시성 제한 시간을 늘리면, 애플리케이션이 메시지를 처리하고 삭제하는 데 더 많은 시간을 가질 수 있습니다. 이는 특히 처리 시간이 길거나 예측할 수 없는 작업에 유용합니다.

<small>The correct answer is D. The visibility timeout is a period during which Amazon SQS prevents other consumers from receiving and processing a message after it has been retrieved by a consumer. If a consumer fails to process and delete a message before the visibility timeout expires, the message becomes visible to other consumers and may be processed again, leading to duplicate processing.

By using the ChangeMessageVisibility API call to increase the visibility timeout, you give the application more time to process and delete the message before it becomes visible to other consumers. This is particularly useful for tasks that may take longer or have unpredictable processing times.</small>

오답 설명

A. CreateQueue API 호출: 새 대기열을 만드는 것은 기존 대기열의 중복 처리 문제를 해결하지 않습니다.
<small>A. CreateQueue API call: Creating a new queue does not address the issue of duplicate processing in the existing queue.</small>

B. AddPermission API 호출: 권한 추가는 메시지 처리 로직을 변경하지 않으므로 중복 문제를 해결하지 않습니다.
<small>B. AddPermission API call: Adding permissions does not change the message processing logic and thus does not solve the duplication issue.</small>

C. ReceiveMessage API 호출: 대기 시간 설정은 메시지 수신 방식을 변경할 수 있지만, 중복 처리 문제를 직접적으로 해결하지는 않습니다.
<small>C. ReceiveMessage API call: Setting a wait time can change how messages are received but does not directly address the duplicate processing issue.</small>

결론

이 문제는 AWS SQS의 중요한 기능인 가시성 제한 시간에 대한 이해를 테스트합니다. 가시성 제한 시간을 적절히 관리하면 메시지의 중복 처리를 방지하고 시스템의 안정성을 향상시킬 수 있습니다. 솔루션 아키텍트로서 이러한 세부 사항을 이해하고 적용하는 것이 중요합니다.

<small>This question tests understanding of the important feature of AWS SQS known as visibility timeout. Proper management of visibility timeout can prevent duplicate processing of messages and improve system reliability. As a solutions architect, it's crucial to understand and apply these details.</small>

원본 문제 링크

댓글

이 블로그의 인기 게시물

Anaconda-Python 환경 VSCode에서 사용하기

Python 웹 크롤링 - Scrapy 활용 파워볼 번호 수집(파일)