ãã®è¨äºã¯MERPAY TECH OPENNESS MONTHã®15æ¥ç®ã®è¨äºã§ãã
ããã«ã¡ã¯ãã¡ã«ãã¤ã®Payment Platformãã¼ã ã§PaymentServiceã®éçºãæ
å½ããã¨ã³ã¸ãã¢ã® @foghost ã§ãã
ã¡ã«ãã¤ã§ã¯ãã¤ã¯ããµã¼ãã¹ã®ã¢ã¼ããã¯ãã£ã§æ±ºæ¸ã·ã¹ãã ãéçºãã¦ãã¾ãããã®ä¸ã§PaymentServiceã¯æ±ºæ¸ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çã®åºç¤ãµã¼ãã¹ã¨ãã¦ãä¸ä½å±¤ã®ãµã¼ãã¹ï¼å¤é¨ãµã¼ãã¹ãå«ãï¼ãæä¾ããå種決æ¸æ段ãå©ç¨ãã¦ãä¸ä½å±¤ã®ãµã¼ãã¹ï¼ã¡ã«ã«ãªãNFCï¼ã³ã¼ãæããªã©ï¼ã«å¿ è¦ãªæ±ºæ¸ããã¼ãå ±éAPIã¨ãã¦æä¾ãã¦ãã¾ããPaymentServiceãæä¾ãã決æ¸å¦çã«è¤æ°ã®ãµã¼ãã¹ãè·¨ãã§ãéã®åããæ£ç¢ºã«ç®¡çããå¿ è¦ãããã®ã§ãä½ãå§ããé ãã決æ¸ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çãæãéè¦ãªèª²é¡ã¨ãã¦ããµã¼ãã¹ãè·¨ãã§ããã¼ã¿ã®æ´åæ§ãåããä»çµã¿ãä½ã£ã¦ãã¾ããã
æ¬è¨äºã§ã¯ããã¤ã¯ããµã¼ãã¹ã«ããã決æ¸ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çã®é£ãããç°¡åãªä¾ã§èª¬æãã¦ããã®å¾PaymentServiceã§å®è·µãã¦ããããã¤ãã®ææ³ãç°¡åã«ç´¹ä»ãããã¨æãã¾ãã
- åæ£ã·ã¹ãã ã«ããããã¼ã¿æ´åæ§æ ä¿ã®é£ãã
- æ¢ç¥ã®ææ³
- PaymentServiceã§å®è·µãã¦ããææ³
- ãããã«
åæ£ã·ã¹ãã ã«ããããã¼ã¿æ´åæ§æ ä¿ã®é£ãã
ãã¤ã¯ããµã¼ãã¹ãSOAãªã©ã®åæ£ã·ã¹ãã ã«ããããã¼ã¿æ´åæ§æ ä¿ã®é£ããã説æããã«ã¯ãã¾ã1ã¤ã®ä¾ãã¿ã¦ã¿ã¾ãããã
ããã客æ§ãå çåºã«å¯¾ãã¦ã2ã¤ã®æ±ºæ¸æ段ã§1000åï¼å é¨ãµã¼ãã¹ã§ç®¡çãããã¤ã³ã600åï¼å¤é¨ãµã¼ãã¹çµç±ã§ã¯ã¬ã¸ããã«ã¼ãã§400åï¼ãæ¯æãå ´åã決æ¸å¦çã¨ãã¦ãã£ãã以ä¸ã®å¦çãå¿ è¦ã¨ãã¾ãã
- 決æ¸å¦çã®ãã©ã³ã¶ã¯ã·ã§ã³ãã¼ã¿ä½æ
- ãã¤ã³ã600åãæ¶è²»ãã
- ã¯ã¬ã¸ããã«ã¼ã400åãæ¶è²»ãã
- å çåºã®å£²ä¸éã«1000åãä»ä¸ãã
- 決æ¸ã®çµæéç¥ãéä¿¡ãã
ä¸ã¯ã·ã¹ãã ä¸ä½ã工夫ããªãå ´åã®ã·ã¼ã±ã³ã¹å³ã§ãããã¹ã¦ãæ£å¸¸ã«å¦çãããå ´åãä¸è¨ã®ããã«â¦çªã¾ã§å®è¡ããã¦æåãè¿ãã¾ããããããç¾å®ã®ä¸çã§ã¯ãããã¯ã¼ã¯ã®é害ããä¾åå ã®ãµã¼ãã¹ã®é害ã絶対çºçããã®ã§ãéä¸ã§å¦çãè½ã¡ãå ´åãã©ããã£ã¦è¤æ°ã®ãµã¼ãã¹ãè·¨ãã§æ±ºæ¸ãã©ã³ã¶ã¯ã·ã§ã³ã®ãã¼ã¿ã®æ´åæ§ãæ ä¿ããã®ãã大ããªèª²é¡ã«ãªãã¾ãã
å ¨é¨ã¯ç¶²ç¾ ãã¾ããããéä¸ã§å¦çãè½ã¡ãå ´åã以ä¸ã®ãããªç¶æ ãçºçããå¯è½æ§ããããã¨æãã¾ãã
- â çªã®ã¨ããã§ã¿ã¤ã ã¢ã¦ããçºçãã
- InternalServiceAã®ä¸ã§ã600åã®ãã¤ã³ããæ¶è²»ãããå¯è½æ§ããã
- â¡çªï¼ãããã¯â¡çªä»¥éï¼ã®ã¨ããã§ãUpper Layer Serviceå´ã§è¨å®ãããã¿ã¤ã ã¢ã¦ãã®æéãè¶
ãã¦ããªã¯ã¨ã¹ããåããã
- PaymentServiceçµç±ãã¦InternalServiceAã®ä¸ã§ã600åã®ãã¤ã³ããæ¶è²»ããããã©ããããããªã
- â¢çªã®ã¨ããã§ã¿ã¤ã ã¢ã¦ããçºçãã
- InternalServiceAã®ä¸ã§ã600åã®ãã¤ã³ããæ¶è²»ããã
- ExternalServiceã®ä¸ã§ã400åã®ä¸ä¿¡æ ãæ¶è²»ããããã©ããããããªã
- â¢çªã®ã¨ããã§ãExternalServiceããæ®é«ä¸è¶³ãªã©ã®ã¢ããªã±ã¼ã·ã§ã³ã¨ã©ã¼ãçºçãã
- InternalServiceAã®ä¸ã§ã600åã®ãã¤ã³ããæ¶è²»ããã
- â£çªã®ã¨ããã§ã¿ã¤ã ã¢ã¦ããçºçãã
- InternalServiceAã®ä¸ã§ã600åã®ãã¤ã³ããæ¶è²»ããã
- ExternalServiceã®ä¸ã§ã400åã®ä¸ä¿¡æ ãæ¶è²»ããã
- InternalServiceBã®ä¸ã§ãå çåºã«1000åä»ä¸ããããã©ããããããªã
- â¤çªã®ã¨ããã§ã¿ã¤ã ã¢ã¦ããçºçãã
- InternalServiceAã®ä¸ã§ã600åã®ãã¤ã³ããæ¶è²»ããã
- ExternalServiceã®ä¸ã§ã400åã®ä¸ä¿¡æ ãæ¶è²»ããã
- InternalServiceBã®ä¸ã§ãå çåºã«1000åä»ä¸ããã
- MessageQueueã«ã¤ãã³ãéä¿¡ããããã©ããããããªã
- â¥çªã®ã¨ããã§ããã¼ã«ã«DBã®ã³ãããã失æãã
- InternalServiceAã®ä¸ã§ã600åã®ãã¤ã³ããæ¶è²»ããã
- ExternalServiceã®ä¸ã§ã400åã®ä¸ä¿¡æ ãæ¶è²»ããã
- InternalServiceBã®ä¸ã§ãå çåºã«1000åä»ä¸ããã
- MessageQueueã«ã¤ãã³ãéä¿¡ããã
- DBã³ãããã«å¤±æããã¨ããã©ã³ã¶ã¯ã·ã§ã³ãã¼ã¿ãªããªããâã®å¦çã§å©ç¨ããããã©ã³ã¶ã¯ã·ã§ã³IDã失ã£ã¦ãã¾ã
ãããã®ã±ã¼ã¹ããããçºçããã¨ãã«ãã©ããã£ã¦ãã³ããªã³ã°ããã°ã客ãã¾ã®ãéãæ£ç¢ºã«ç®¡çã§ããã®ãããä¸åº¦èãã¦ã¿ãã°ãåæ£ã·ã¹ãã ã«ããããã¼ã¿æ´åæ§æ ä¿ã®é£ãããå°ãåãã£ã¦ããã ãããã¨æãã¾ãã
æ¢ç¥ã®ææ³
åæ£ãã©ã³ã¶ã¯ã·ã§ã³ã¢ãã«ã¨ãã¦ãXAã¨è¨ã£ããããã³ã«ãæããæå±ããã¦ããã2PCï¼2 phase commitï¼ãªã©ã®ææ³ãããç¥ããã¦ãã¾ããMySQLã§ã2PCã«ããXAãã©ã³ã¶ã¯ã·ã§ã³æ©è½ãæä¾ãã¦ãã¾ãããã ãã2PCã®å ´åãå®è¡ä¸ãã¹ã¦ã®åå è ããããã¯ããããªã©ã®åé¡ããããæ§è½ã¨å¯ç¨æ§ä¸ã®æ¸å¿µãããã¾ãã
ããã¦ãXAã®ãããªã°ãã¼ãã«ãã©ã³ã¶ã¯ã·ã§ã³ã¨ãã¦ACIDç¹æ§ãæ ä¿ãããææ³ã«å¯¾ãã¦ãEric Breweræ°ããCAPå®çãã¨ä¸ç·ã«ãBASEãã¨ããå¯ç¨æ§ãæ§è½ãéè¦ããåæ£ã·ã¹ãã ã®ç¹æ§ã2000å¹´é ã«ææ¡ãã¾ããã
ãCAPå®çãã¯ãåæ£ã·ã¹ãã ã«ããã¦ä»¥ä¸ã®3ã¤ã®è¦ç´ ã2ã¤ããåæã«æºãããã¨ãã§ããªããã¨ã示ãã¾ãã
- C: Consistency (ä¸è²«æ§)
- A: Availability (å¯ç¨æ§ï¼
- P: Tolerance to network Partitions (ãããã¯ã¼ã¯åæã¸ã®èæ§)
ãBASEãã¨ããã®ããåºæ¬çã«ã¯å¸¸ã«å©ç¨å¯è½ã§ãä¸æçã«ä¸è²«æ§ã®ãªãç¶æ ã許容ãã¦ãå³æã§ã¯ãªãçµææ´åæ§ãåãç¹æ§ã«ãªãã¾ããã¤ã¾ãCAPã®ä¸ã§APãéè¦ãã¦ãCï¼Consistencyï¼ã®ã¨ãããå°ãç·©ããã·ã¹ãã ãæã¤ç¹æ§ã§ãã
å®éã®ãµã¼ãã¹éçºã«ãããBASEã®å¿ç¨ä¾ã¯ã2008å¹´eBayã®Pritchettæ°ãæ¸ãã ãBase: An Acid Alternativeããã¿ã¦ããã ããã¨ã¤ã¡ã¼ã¸ãããã¨æãã¾ãã
ã¾ãä¸å½ã§äººæ°ã®ã¢ãã¤ã«æ±ºæ¸ãµã¼ãã¹ã¢ãªãã¤ï¼å·çæç¾å¨(2019å¹´6æ)10åã¦ã¼ã¶ã¼ã«å©ç¨ããã¦ããï¼ã2008å¹´é çºè¡¨ãããã¼ãã¼ãã«ãã大è¦æ¨¡SOAã·ã¹ãã ã«ãããBASEã®å¿ç¨äºä¾ãæ¸ããã¦ãã¾ããTCCï¼Try/Confirm/Cancelï¼ãè£åãã©ã³ã¶ã¯ã·ã§ã³ãªã©ã®ææ³ãå©ç¨ãã¦BASEç¹æ§ã«æºãã決æ¸ã·ã¹ãã ãå½æããä½ãä¸ãã¦ããããã§ãã
TCCã¨ããã®ã¯ãã¡ã¤ã³ãµã¼ãã¹ãä¾åå ãµã¼ãã¹ã®ããå¦çï¼ä¾ãã°æ®é«ãæ¸ããï¼ãè¡ãã¨ãã«ãä¾åãµã¼ãã¹å´ã§è©²å½ããå¦çãTry/Confirm/Cancelã¨ãã3ã¤ã®å¦çãAPIã¨ãã¦æä¾ãã¦ãã¡ã¤ã³ãµã¼ãã¹ã¯ã³ã¼ãã£ãã¼ã¿ã¼ã®å½¹å²ãæããã¦ãããã®æä½ã使ã£ã¦å ¨ä½ã®ãã¼ã¿æ´åæ§ï¼çµææ´åæ§ï¼ãæ ä¿ããææ³ã§ãã
- Try: ä¾åããå ã®ãµã¼ãã¹å´ã§å¦çã«å¿ è¦ãªãªã½ã¼ã¹ãç¶æ ãªã©ã®ä»®æ¼ãããè¡ããTryã§æ¼ããããããããConfirmå¦çãå¿ ãæåããããããã¯Cancelå¦ççµç±ã§ãã¼ã«ããã¯ãã§ããã®ããã¤ã³ãã§ãã
- Tryå¦çã®ãã§ã¼ãºã§ãä¾åå ã®Tryå¦çãä¸ã¤ã§ã失æï¼ã¿ã¤ã ã¢ã¦ããªã©ï¼ããããæåãããµã¼ãã¹ã®Cancelå¦çãããããæåã¾ã§å®è¡ãã¦ãã¼ã«ããã¯å¦çãè¡ã
- Tryå¦çããã¹ã¦æåããããä¾åå ã®ãµã¼ãã¹ã®Confirmå¦çãæåã¾ã§å®è¡ããã
PaymentServiceã§å®è·µãã¦ããææ³
æ¢ã«è¿°ã¹ãããã«ãPaymentServiceã§ã¯ã客æ§ã®ãéãæ£ç¢ºã«ç®¡çãããããåæãããã©ã³ã¶ã¯ã·ã§ã³ç®¡çã®èª²é¡ã¨åãåã£ã¦ãè¤æ°ã®ãµã¼ãã¹ãè·¨ãã§ãå ¨ä½çãªæ±ºæ¸ãã©ã³ã¶ã¯ã·ã§ã³ã®æ´åæ§ãæ ä¿ã§ããä»çµã¿ã模索ããªããä½ã£ã¦ãã¾ããã
ãã¤ã¯ããµã¼ãã¹ãã¨ã«å©ç¨ãããã¹ãã¬ã¼ã¸ã¯ç°ãªãå¯è½æ§ããããã¯ã¬ã¸ããã«ã¼ãçã®å¤é¨ãµã¼ãã¹ã¨ã®æ´åæ§ãåãå¿ è¦ããããããPaymentServiceã§ã¯æåããDBãæä¾ããXA(2PC)ãªã©ã®åæ£ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çæ©è½ã«ä¾åããªãæ¹åã§ãã¢ããªã±ã¼ã·ã§ã³ã®ã¬ã¤ã¤ã¼ã§ãã¼ã¿æ´åæ§ã®æ ä¿ããæ¦ç¥ãæ¡ç¨ãã¦ãã¾ããã
çµæçã«eBayãã¢ãªãã¤ã§ãå®è·µãã¦ãããããªå¯ç¨æ§ã¨æ§è½ãéè¦ããçµææ´åæ§ãåããã·ã¹ãã ã«ãªã£ã¦ãã¾ããããããã¯å®éã«ãã£ã¦ããããã¤ãã®ææ³ã«ã¤ãã¦ç´¹ä»ãã¾ãã
決æ¸ãã©ã³ã¶ã¯ã·ã§ã³å¦çã®ç´°åå
決æ¸å¦çä¸ã«ã¨ã©ã¼ãçºçããå ´åãçºçããã¨ã©ã¼ã®ç¨®é¡ã¨å¦çãã©ãã¾ã§é²ããã®ãã«ãã£ã¦ãåãã¹ããã³ããªã³ã°ãåããã¾ãã
- ãªãã©ã¤ãã¦ç´ããåé¡ã§ããã°ãå¿
è¦ãªãªãã©ã¤å¦ç ãè¡ã
- å³æã§ãªãã©ã¤ã§ããªãã£ãå ´åããããã§ãã¨ã§ãªãã©ã¤ãããã¿ã¼ã³ããã
- ãªãã©ã¤ã§ç´ããªãåé¡ã§ããã°ãä¾åå ã®ãµã¼ãã¹å«ãã¦ãå¿ è¦ãªãã¼ã«ããã¯å¦ç ãå®è¡ãã¦ãããå¦çãçµäºãã
ãã®ä¸ã§ã å¿ è¦ãªãªãã©ã¤å¦ç ã¨ å¿ è¦ãªãã¼ã«ããã¯å¦ç ãå¤æããã«ã¯å¦çãã©ãã¾ã§é²ããããã¾ãç¥ãå¿ è¦ãããã¾ãã
ã¯ããã«ãããä¾ã§ã¯ã1ã¤ã®å¤§ãããã©ã³ã¶ã¯ã·ã§ã³å¦çã¨ãã¦å®è¡ãããã®ã§ãéä¸ã§å¦çãè½ã¡ãå ´åãã©ãã§è½ã¡ãã®ãããããªããªãã®ã§ããã¨ã§å¾©æ§ãå°é£ã«ãªãã¾ãã
PaymentServiceã§ã¯1ã¤ã®æ±ºæ¸ãã©ã³ã¶ã¯ã·ã§ã³å¦çãè¤æ°ã®ãã§ã¼ãºã«ç´°ååãã¦å®è¡ããããã«ãã¦ãã¾ãã
- 決æ¸å¦çãåä»æã«å é¨ãã©ã³ã¶ã¯ã·ã§ã³ãã¼ã¿ã¨IDãå¿ ãä¸ã¤ã®ãã§ã¼ãºã¨ãã¦ç¢ºå®ãã¦ããå¦çãã
- ãã§ã¼ãºã®é²è¡ç¶æ ãå¿ ãè¨é²ãã
- ãã§ã¼ãºã®ç²åº¦ã¯ãªãã©ã¤ã¨ãã¼ã«ããã¯å¦çã®ãããããã«ãã£ã¦æ±ºãã
- ä¾åå ã®ãµã¼ãã¹ã«å¯¾ãã¦1ã¤æä½ããå ´åãåºæ¬1ã¤ã®ãã§ã¼ãºã¨ãã¦åãã¦ãæä½æã®ãã°ãç´°ããæ®ãããã«ãã¦ãã
å¦çã®ç´°ååã«ãã£ã¦ãå¦çæãããã¯éä¸ã§è½ã¡ãã¨ãã¦ããç¾å¨è¨é²ããã¦ãããã§ã¼ãºãåç §ãã¦ãåãã¹ããªãã©ã¤ãããã¯ãã¼ã«ããã¯å¦çã®ç¯å²ãçµããªãããããç°¡åã«å¾©æ§ã§ãã¾ãã
ã¹ãã¼ãâãã·ã³ã§å®è£ ãããã³ã¼ãã£ãã¼ã¿ã¼
ãã決æ¸å¦çã®ç¶æ é·ç§»ããã®ããã«ãªã£ã¦ããã¨ãã¾ãã
- Created: 決æ¸åä»
- Paid: æ¯æãæåãã
- Failed: æ¯æã失æãã
- Refunded: è¿éãããå ´åãè¿éããã
ä¸ã§èª¬æãã決æ¸å¦çã®ç´°ååãè¡ã£ããã¨ãåå¦çãã§ã¼ãºããã種ã®ä¸éç¶æ ã«ãªãã¾ããPaymentServiceã§ã¯ãåå¦çãã§ã¼ãºã®ã¹ãã¼ãå®ç¾©ãå¿ è¦ãªå¦çãç¶æ é·ç§»ãå«ãã¦æ±ºæ¸å¦çãã¨ã«å®ç¾©ãã¦ãã¹ãã¼ããã·ã³ã®ä»çµã¿ã使ã£ã¦æ±ºæ¸ã®ãã©ã³ã¶ã¯ã·ã§ã³å¦çã®ã³ã¼ãã£ãã¼ã¿ã¼ãå®è£ ãã¦ãã¾ãã
ã¹ãã¼ããã·ã³ã§å®è£ ããã¡ãªããã¯ä»¥ä¸ã®ã¨ãããããã¾ãã
- ãã¬ã¼ã ã¯ã¼ã¯åããããããæåãã決æ¸å¦çã®ç´°ååãèããªããå®è£ ããã
- åãã§ã¼ãºã§ã¨ã©ã¼çºçããã¨ãã«ãããããã®ãã§ã¼ãºãå¿
è¦ã«å¿ãã¦ããªãã©ã¤ãããã¯ãã¼ã«ããã¯å¦çãå®è¡ãããã¨ãã§ãã
- ãªãã©ã¤å¦çã®ç¯å²ãçµãããããªããå¿ è¦ãªåã ãå®è¡ããã°ãã
- ãã¼ã«ããã¯æã®ãã©ã³ã¶ã¯ã·ã§ã³ããããããã®ãã§ã¼ãºãå¿ è¦ãªRollbackå¦çãç¶æ é·ç§»ã«è¿½å ããã°å®è£ ã§ãã
- ç´°ååãããåãã§ã¼ãºã®å®è¡ç¶æ
ã®ç®¡çã¯ã¹ãã¼ããã·ã³ã§ã®å
±éã®ä»çµã¿ã§ç®¡çããããããç¹ã«æèããªãã¦ãèªç¶ã§çµ±ä¸çã«ç®¡çããã
- 管çãããç¨åº¦çµ±ä¸ããããããèªå復æ§ã®ä»çµã¿ãå ±éã§ä½ãããããªã
- ãã§ã¼ãºã®å ±éåãããããããªã
ãã¡ãªãããããã¤ãããã¾ãã
- ããã°ã©ã ãä¸ããé çªã«æ¸ããã¦ããªãã®ã§ãããã°ã©ãã³ã°ã®é£æ度ãå°ãé«ããªãã
- æ°ã¡ã³ãã¼ãå ¥ã£ãã¨ããæ £ããã¾ã§ãã£ããã¢ããã®æéããããã
- ç¶æ
é·ç§»ã§ã¤ãªããå¦çãããªã¬ã¼ã«ãã£ã¦ã«ã¼ããå¤ãããã¨ãããã®ã§ãé ã®ä¸ã§ãäºæ¸¬å¯è½ï¼Predictableï¼ãªããã°ã©ã ãæ¸ãã®ã«å·¥å¤«ãå¿
è¦
- ãã¹ããæ¸ããã¨ãã¨ã¦ã大äºã«ãªã
- ãããã°ã®é£æ度ãä¸ãããé©åã«ãã°ãæ®ãã®ã大äº
- ãã§ã¼ãºã®å®ç¾©ãç´°ããããã¨ãããã©ã¼ãã³ã¹ã«å½±é¿ãä¸ãã¦ãã¾ãå¯è½æ§ããã
åªçæ§
決æ¸å¦çä¸ãªãã©ã¤å¦çãçºçããå ´åãä½ãèæ ®ããªãå ´åãä¾åå ãµã¼ãã¹ã«æããæä½ãå¤éã«å®è¡ããããã客æ§ã®æ®é«ãä½åº¦ãå¼ããã¦ãã¾ãåé¡ãçºçãã¾ãã
ãã®ãããªæä½ãå¤éã«å®è¡ãã¦ãçµæï¼æ®é«ãä¸åº¦ã®ã¿å¼ãããï¼ãå¤ãããã¨ããªãç¹æ§ã®ãã¨ããåªçæ§ã¨å¼ã³ã¾ãã
決æ¸å¦çã®åªçæ§ãæ ä¿ããããã主ã«2ã¤ã®æ段ãèãããã¾ãã
- æä½çµæãåç §ããæ段ãç¨æãã¦ãå¼ã³åºãå´ã§åå®è¡ããåã«å¿ ãçµæã確èªãã¦ããè¡ã
- å¼ã³åºãããå´ã®æä½èªä½ãåªçæ§ãæ ä¿ãããåæã§ä½ã£ã¦ãä½åº¦ãå®è¡ãã¦ãåãçµæã«ãªã
1ã®å ´åãåå®è¡ããã¨ãã«åç §ãããã1ãªã¯ã¨ã¹ããæããå¿ è¦ãããããå ´åã«ãã£ã¦ããã©ã¼ãã³ã¹ã«å½±é¿ãåºãå¯è½æ§ãããã¾ããããã¦å®è£ ä¸åç §ãã¦çµæ確èªããå¦çãããæ¼ããããäºæ ã®å ã«ãªãã®ã§ãã¡ã«ãã¤ã§ã¯ãåºæ¬çã«2ã®æ¹éã§åãµã¼ãã¹ãåªçæ§ã®ããAPIãæä¾ãããã¨ãå¼·ãè¦æ±ããã¦ãã¾ãã
- APIã®æä¾å´ã¯ããªã¯ã¨ã¹ãã®ãã©ã¡ã¼ã¿ã¨ãã¦Idempotency Keyãå¿ ãåãåã£ã¦åªçæ§æ ä¿ã§ããããã«å®è£ ãã
- APIã®å©ç¨å´ã¯ãå¤éå¦çãããªãããã«ã¦ãã¼ã¯ãªIdempotency Keyãçæãã¦APIãå©ã
PaymentServiceã®å ´åã決æ¸å¦çãåãä»ããã¨ãã«å é¨ã®ãã©ã³ã¶ã¯ã·ã§ã³IDãä¸åº¦ç¢ºå®ãã¦ããã客æ§ã®æ®é«ãæ¸ããæä½ãã¦ãã¾ããããã¦ãæ®é«ãæ¸ããã¨ãã«ãä¾åå ã®ãµã¼ãã¹ãæä¾ããæ®é«æä½APIï¼åªçæ§ãæ ä¿ããã¦ããï¼ã«ç¢ºå®ãããå é¨ã®ãã©ã³ã¶ã¯ã·ã§ã³IDãIdempotency Keyã¨ãã¦æ¸¡ãã°ãä½åº¦ãå®è¡ãã¦ãæ®é«ãä¸åº¦ã ãå¼ããããã¨ãä¿è¨¼ããã¾ãã
è£åãã©ã³ã¶ã¯ã·ã§ã³
決æ¸å¦çã®éä¸ã§ãã©ããã¦ãåã«é²ããããªãå ´åãä»ã¾ã§å®è¡ãã¦ããæä½ãä¸åº¦ãã¡ãã¨ãã¼ã«ããã¯ãã¦ãã失æãè¿ãå¿ è¦ãããã¾ãããã®ããã®å¦çãè£åãã©ã³ã¶ã¯ã·ã§ã³ã¨å¼ã°ãã¦ãã¾ãã
ä¾ãã°ã¯ããã«æ¸ããä¾ã ã¨ãå é¨ãµã¼ãã¹ï¼InternalServiceAï¼ã管çããããã¤ã³ãã®æ¶è²»ã確å®ãããå¾ãå¤é¨ãµã¼ãã¹ï¼ExternalServiceï¼ã¯ã¬ã¸ããã«ã¼ãã§ã®æ±ºæ¸ã失æãããããã®ã¾ã¾ã§å¦ççµäºãã¦å¤±æãè¿ãã¨ãã客æ§ã«ã¨ã£ã¦æ±ºæ¸ã失æããã®ã«ããã¤ã³ããæ¶è²»ãããç¶æ ã«ãªã£ã¦ãã¾ã£ã¦ä¸æ´åãçºçãã¾ãã
PaymentServiceã§ã¯ãæ£å¸¸ã®ãã©ã³ã¶ã¯ã·ã§ã³å¦çã¨å ±ã«ããã¼ã«ããã¯ããããã®è£åãã©ã³ã¶ã¯ã·ã§ã³å¦çãã¹ãã¼ããã·ã³ã§ç®¡çãã¦ãå¿ è¦ã«å¿ãã¦å®è¡ãã¦æ±ºæ¸å¦çã®æ´åæ§ãæ ä¿ãã¦ãã¾ãã
ã¾ã ãè£åå¦çã¨ãã¦ãããããã«ãã¼ã«ããã¯ãããã¨ããä¸ã§ç´¹ä»ããTCCã®ããæ¹ã¨åããã1ã¤ã®æä½ãä»®æ¼ããã¨å®è¡ã®ï¼ã¤ã®åå²ããææ³ãæ¡ç¨ãã¦ãã¾ãã
ä¾ãã°æ®é«æ¶è²»ã®å¦çã«ã¯éé¡ã®æ¶è²»ã¨å±¥æ´ã®è¨é²å¦çããã£ãå ´åãä¸ã¤ã®æä½ã«ã¾ã¨ããã¨ããã¼ã«ããã¯å¦çãå®è¡ãããå¾ã«éé¡ã¯æ£ããè¿ãã¾ãããå±¥æ´ãæ±ããåé¡ãçºçãã¾ãã
ããã«å¯¾ãã¦ãä»®æ¼ããã¨å®è¡ã®2ã¤ã«åããã
- ä»®æ¼ããã®æ®µéã§ã¯ãæ®é«ã仮売ä¸ç¶æ ã¨ãã¦æ¼ãããã ã
- å®è¡ãããå®å£²ä¸ã¨å±¥æ´ã®è¨é²å¦çãèµ°ã
ä»®æ¼ããã®å¾ã«ãã¼ã«ããã¯å¦çãèµ°ã£ãããå±¥æ´ãæ±ãããªã©ã®å¯ä½ç¨ãæããªããããããããªè£åå¦çãå®ç¾ã§ãã¾ãã
ãªã³ã³ãµã¤ã«
ããã¾ã§ã¯ã¢ããªã±ã¼ã·ã§ã³ã¬ã¤ã¤ã¼ã§æ±ºæ¸å¦çã®æ´åæ§ãæ ä¿ããææ³ã«ã¤ãã¦èª¬æãã¦ãã¾ããããå®éã«ã·ã¹ãã ã«ä½ãè¾¼ãã§æ¬çªã«ãªãªã¼ã¹ããå¾ãæ¬å½ã«æ±ºæ¸å¦çã®ãã¼ã¿æ´åæ§ãã¡ããã¨åãã¦ããã©ããã«ã¤ãã¦ãä½ããã®æ¹æ³ã§ç¢ºèªãããã¯ã¢ãã¿ãªã³ã°ããå¿ è¦ãããã¾ããã¡ã«ãã¤ã§ã¯åãµã¼ãã¹éã®ãã©ã³ã¶ã¯ã·ã§ã³ãã¼ã¿ã®ãªã³ã³ãµã¤ã«ï¼ãã¼ã¿çªåï¼å¦çãè¡ã£ã¦ãã¾ããä¸ãä¸ä¸æ´åãæ¤ç¥ããããæ©æ¥ã®å¾©æ§å¯¾å¿åã³ä»å¾åãã®æ ¹æ¬å¯¾çãæ±ãããã¦ãã¾ãã
PaymentServiceã§ã¯ãå é¨ãã©ã³ã¶ã¯ã·ã§ã³å¦çã®ä¸æ´åæ¤ç¥ã¨èªå復æ§ãè¡ã£ãä¸ã§ããããå¦çã§ä¼è¨ãã¼ã¿ãæ®é«ãªã©ã®ç®¡çã·ã¹ãã ã¨ã®ãªã³ã³ãµã¤ã«ãè¡ã£ã¦ãã¾ããã¾ããPaymentServiceã«ä¾åããä¸ä½ã¬ã¤ã¤ã¼ã®ãµã¼ãã¹ãåããPaymentServiceã¨ã®ãªã³ã³ãµã¤ã«ãè¡ããã¡ã«ãã¤å ¨ä½ã®æ±ºæ¸ã·ã¹ãã ã®æ´åæ§ãæ ä¿ããããã«ãã¦ãã¾ãã
ãªã³ã³ãµã¤ã«ã®ææ³ã¯ä¸»ã«ä»¥ä¸ã®2ã¤ã使ããã¦ãã¾ãã
- ãããã§ãã¼ã«ã«ã§ç¢ºå®ããåªçãã¼ããã©ã³ã¶ã¯ã·ã§ã³IDã使ã£ã¦ãä¾åå ã®ãµã¼ãã¹å´ãæä¾ããåç §APIã§åæçã«ãã¼ã¿ã®çªåãè¡ã
- ä¾åãããµã¼ãã¹å´ãéåæã§éä¿¡ããçµæã¤ãã³ããå©ç¨ãã¦ããã¼ã«ã«ã®ãã©ã³ã¶ã¯ã·ã§ã³ãã¼ã¿ã¨éåæçã«çªåãè¡ã
Fault Injection Testing
決æ¸å¦çãå®è£ ããã¨ããæ£å¸¸å¦çãããç°å¸¸å¦çã®ã»ããæ°åé£ããã§ãã
çæ³ä¸ãçºçããããã¹ã¦ã®ç°å¸¸ã±ã¼ã¹ã®ä¸è¦§ãããã°ãããã¾ã§ç´¹ä»ããææ³ãã¡ããã¨åãè¾¼ãã°ãªãªã¼ã¹åãããã¹ã¦ã®ç°å¸¸ãã³ããªã³ã°ãã§ãã¦ããã¼ã¿æ´åæ§ãèªåçã«æ ä¿ã§ããã¯ãã§ãã
ãã ããç¾å®ã®ä¸çã§ã¯ãããªç°å¸¸ã±ã¼ã¹ã®ä¸è¦§ãã©ãã«ãæ確åããã¦ãã¾ããããã¸ãã¹ãã¸ãã¯ä¸ã®å é¨è¦å ã§çºçããç°å¸¸ã±ã¼ã¹ã®æ´ãåºãã¯ã¾ã ç°¡åã§ããããããã¯ã¼ã¯åé¡ãä¾åå ãµã¼ãã¹ã®é害ãªã©ã®å¤é¨è¦å ã«ããç°å¸¸ã±ã¼ã¹ã®æ´ãåºããäºæ¸¬ã¯ç°¡åã§ã¯ããã¾ããã
PaymentServiceã§ã¯å¤é¨è¦å ã§çºçããç°å¸¸ã±ã¼ã¹ãå®è¡ä¸ã«ã©ã³ãã ã«çºçãããããã«ãFault Injection Testingã®ä»çµã¿ãä½ããã¦ãã¾ããä¾ãã°ããããã¯ã¼ã¯ã«ããã¿ã¤ã ã¢ã¦ããDBããç°å¸¸ã¨ã©ã¼ã®çºçãä¾åããå¤é¨ãµã¼ãã¹ã¸ã®æ¥ç¶ä¸å®å®ãªã©ãå ±éã®ã¤ã³ã¸ã§ã¯ã·ã§ã³ã±ã¼ã¹ã¨ãã¦ç¨æãã¦ãå ¨ã¦ã®æ±ºæ¸å¦çã¯Unit Test, e2e Test以å¤ãFault Injection Testãå¿ é ã«ãããã¨ã§ãå®è£ ãããç°å¸¸ã±ã¼ã¹ã®ãã³ããªã³ã°ã®ç¶²ç¾ 度ãæ¤è¨¼ã§ãã¾ãã
ããã¦ããã®ãããªä»çµã¿ã«ãã£ã¦ãæ°ããéçºãã決æ¸APIã§ãããªãªã¼ã¹ããªãã¦ãæ¬æ¥äºæ¸¬å°é£ãªç°å¸¸ã±ã¼ã¹ãäºåã«çºçããããã¨ã§ããã¼ã¿ä¸æ´åãåªçæ§ã®åé¡ãäºåã«è§£æ¶ã§ããããé«ãå質ã§ãªãªã¼ã¹ã§ãã¾ãã
ãããã«
以ä¸ããã¤ã¯ããµã¼ãã¹ã¢ã¼ããã¯ãã£ãæ¡ç¨ããã¨çµ¶å¯¾ä¸åº¦ã¯æ©ã¾ããããã©ã³ã¶ã¯ã·ã§ã³ç®¡çã®è©±ã§ãããããã«ç´¹ä»ããã以å¤ã®ææ³ãè²ã ãããã¨æãã¾ããããã¦ã¡ã«ãã¤ã¯ã¾ã ã¹ã¿ã¼ãããã°ãããªã®ã§ãããããããããã¯ãã®é²åã¨ã¨ãã«ã常ã«ããæ¹æ³ã模索ããªãã決æ¸ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çã®ä»çµã¿ãé²åããã¦è¡ãããã¨æãã¾ãã