공공임대주택 공공데이터 API를 활용해 다음과 같은 화면을 구성해야 하는 일이 생겼습니다!
지역별로 쉐어하우스의 개수를 지도에 표시하는건데요, 이를 청년주택 데이터로 구마다 표시하려면 어떻게 해야 할까요?!
다음과 같이, 공공데이터 홈페이지에서 OPEN API를 제공해줍니다!
사용법은 위의 그림과 같습니다 쿼리스트링 방식으로, 해당 변수에 값을 넣어서 HTTP 요청 메세지를 보내면 되는데요, 예시로는 아래 그림과 같습니다.
HTTP 응답 메세지에서 totalCount값이 98임을 확인할 수 있습니다! 즉, 서울특별시 중구에는 98개의 공공임대주택이 있다는 것이죠!
그런데, 위에서 봤던 쉐어하우스 우주 홈페이지와 같이 서울의 모든 구마다 주택의 개수를 표현하고자 한다면, 이 요청을 구마다 반복해야 할까요?
서울의 구는 25개인데 홈페이지에 들어오는 사람마다 지도를 표시하고자 한다면, 1명당 OPEN API 25번의 요청을 보내고 자체 서버가 있다면 추가로 1번을 더해야 합니다.
그러면 총 1명당 26번의 네트워크를 타게 되는데, 이렇게 설계하는게 옳은 방법일까요?
추가로, OPEN API의 일일 트래픽 제한은 1000번입니다. 사용자가 하루에 약 50명들어온다고 가정한다면, 서비스가 제대로 작동하지 못하는 상황이 발생합니다.
그렇다면, 이를 어떻게 해결해야 할까요?
수동으로 OPEN API를 직접다 호출하고, DB에 넣을 수 있지만 데이터가 변했을 경우, 올바른 데이터를 사용자들에게 제공할 수 없습니다. 예를 들어 날씨공공데이터같은경우엔, 매일마다 데이터가변할텐데 말이죠!
그래서.. 변하는 데이터들을 빠르게 반영하고 네트워크도 적게 탈 수 있는 방법이 어떤게 있을까 생각해봤습니다.
구글링을 해보니.. Spring Batch 로 일괄처리를 진행하고 Quartz를 이용해 스케쥴러 기능을 이용할 수 있음을 파악할 수 있었습니다!
즉, Spring Batch, Quartz를 이용해 반복적으로 데이터들을 DB에 넣어놓고 직접 Spring Server에서 API를 설계해서 클라이언트에게 제공하는 방법을 사용하는게 효율적일 것이라고 판단했습니다!
간략하게 그림으로 나타내자면 아래 그림과 같이 표현할 수 있습니다!
Spring Batch를 배우기 위해 인프런에서 강좌를 찾아보니,,
무려 45시간이나 되는 강좌가 있음을 확인했습니다..
평소에 Spring Batch를 들어만 봤지만 어떤 경우에 사용하는지 명확히 알기어려웠습니다!
하지만, 이런 기능이 정말 필요한데 이미 잘 만들어진 기술이 있을까? 찾아보는 과정에서 왜 배워야 하는지 명확히 알 수 있었고 확실한 동기부여를 얻을 수 있었습니다!
얼마나 오래 걸릴지 모르겠지만, 다음포스팅에서 찾아뵙겠습니다!