Merpay Advent Calendar 2019 ã®19æ¥ç®ã¯ãBackendã¨ã³ã¸ãã¢ãã¼ã ã® @toshinao ããéããã¾ãã
æ°ãããã¤ã¯ããµã¼ãã¹ãç«ã¡ä¸ããæ©ä¼ããããã¯ãªã¼ã³ã¢ã¼ããã¯ãã£ããã¼ã¹ã«ãã¾ãããã¯ãªã¼ã³ã¢ã¼ããã¯ãã£ã¯ããã¯ã¨ã³ãã»ããã³ãã¨ã³ãã»ã¢ããªãªã©æ§ã
ãªå ´æã§æ¡ç¨ããã¦ãã¾ãããã ã確åºããæ¹æ³ã¨ããã®ã¯ç¡ããã¿ãªè©¦è¡é¯èª¤ãã¦ããã®ã§ã¯ç¡ãã§ããããããã®è¨äºã§ã¯ãã¯ãªã¼ã³ã¢ã¼ããã¯ãã£ãåãå
¥ããä¸ã§èãããã¨ãç´¹ä»ãããã¨æãã¾ãã
ãã¤ã¯ããµã¼ãã¹ãä½ã£ããã¨ããªã人ããä»ã¾ã§ããã¤ãä½ã£ã¦ãããã©ããè¯ãè¨è¨ã«ã¤ãã¦èãã¦ãã人ã®å©ãã«ãªãã°å¹¸ãã§ãã
ã¯ããã«
ã¡ã«ãã¤ã®ããã¯ã¨ã³ãã¯ä¸»ã«Goã¨Google Cloud Platformï¼GCPï¼ã§éçºãè¡ã£ã¦ãã¾ãããåãã¤ã¯ããµã¼ãã¹ãã©ãå®è£ ãã¦ãããã¯æ¦ãåãã¼ã ã«å§ãããã¦ãã¾ããä»åãè¨è¨ããã«ããã£ã¦ä¸è¨ã®æ¬ãåèã«ãã¾ããã
- ã¨ã³ã¿ã¼ãã©ã¤ãºã¢ããªã±ã¼ã·ã§ã³ã¢ã¼ããã¯ãã£ãã¿ã¼ã³ (以éPoEAAã¨è¡¨è¨)
- ã¨ãªãã¯ã»ã¨ã´ã¡ã³ã¹ã®ãã¡ã¤ã³é§åè¨è¨ (以éEvansæ¬ã¨è¡¨è¨)
- Clean Architectureãé人ã«å¦ã¶ã½ããã¦ã§ã¢ã®æ§é ã¨è¨è¨ (以éClean Architectureæ¬ã¨è¡¨è¨)
主ã«èãããã¨ã¯ä¸è¨ã®ãããªäºã«ãªãã¾ãã
- ã¬ã¤ã¤ã¼ãã¨ã®è²¬åãã¯ã£ããã¨ããã
- ã¬ã¤ã¤ã¼éã®ã«ã¼ã«ãå³æ ¼ã«ãã
- æ§ã ãªå ¥åºåãçµ±ä¸çã«æ±ããããã«ãã
- æ°¸ç¶åã³ã¼ããå³æ ¼ãªã«ã¼ã«ãé©ç¨ãã
å²ã¨ãã£ã¡ãã¨ããè¨è¨ã¨ãªã£ã¦ãã¦Goã£ã½ãã¯å°ãªãããããã¾ããã
ã¬ã¤ã¤ã¼ãã¨ã®è²¬åãã¯ã£ããã¨ããã
éå»ã«ãã¤ã¯ããµã¼ãã¹ãç¬èªã®ã¬ã¤ã¤ã¼æ§æã¨ã¬ã¤ã¤ã¼åã§ä½æããã¨ãããåè¦ã®äººã«ã¯åããã«ãããå¦ç¿ã³ã¹ããé«ããã®ã¨ãªã£ã¦ãã¾ãã¾ããã
ãã®ãããä»åã¯æ®åãã¦ããã¬ã¤ã¤ã¼æ§æã«ãããã¨ã§åã¬ã¤ã¤ã¼ã®è²¬åãææ¡ããããããã±ã£ã¨è¦ãã ãã§ã©ãã«ä½ããããã¤ã¡ã¼ã¸ã§ããããã«å¿ããã¾ããã
ã¾ããèªåèªèº«ããã¼ã¹éçºãè¡ã£ã¦ããä¸ã§ã¬ã¤ã¤ã¼ã®è²¬åãæ確ã ã¨ãã©ãã«ä½ãæ¸ãã¹ããã®æ ¹æ ä»ããã¯ã£ããããã®ã§è¯ãã£ãã¨æãã¾ããã
ã¬ã¤ã¤ã¼ã¯ä¸è¨ã®ç»åã¨åãæ§æã«ãã¦ãã¾ãã(ã«ãã³å ã¯ãã£ã¬ã¯ããªåã§ãã)
- 1 Frameworks & Drivers (drivers)
- 2 Interface Adapters (adapters)
- 3 Application Business Rules (usecases)
- 4 Enterprise Business Rules (domain)
1 Frameworks & Drivers
Cloud Spanner ãCloud Pub/Subãgrcp.Dialãªã©ã®èãã©ããã¼ãè¨è¿°ãã¾ãã
ã©ã¤ãã©ãªå´ã§ã¤ã³ã¿ã¼ãã§ã¼ã¹ãåå¨ããã°ãããããã®ã¾ã¾ä½¿ãå ´åãããããã®ã¬ã¤ã¤ã¼ãã¹ãããããå ´åãããã¾ããã
2 Interface Adapters
å
¥åã®ããªãã¼ã·ã§ã³ããªãã©ã¤å¶å¾¡ãªã©æ¥åãã¸ãã¯ãä»å¨ããªãå¦çãè¨è¿°ãã¾ãã
ã¾ããSpannerã®ã¯ã¨ãªãé£æºãã¤ã¯ããµã¼ãã¹ã¸ã®ãªã¯ã¨ã¹ããããã«è¨è¿°ãã¾ãã
3 Application Business Rules
ã¡ã¤ã³ã®æ¥åãã¸ãã¯ãæ¸ãã¾ããSpannerã®ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çã¯ããã§è¡ã£ã¦ãã¾ãã
注å
¥ããã¦ããInterface Adaptersã¬ã¤ã¤ã¼ã®ã¤ã³ã¹ã¿ã³ã¹ã使ã£ã¦å¤é¨ã¨ã®ããåãããã¾ãã
4 Enterprise Business Rules
Spannerã®ãã¼ãã«æ§æã¨ç¬ç«ãããæ§é ä½ãå®ç¾©ãã¾ãã
ããã«è¨è¿°ããã®ã¯ããã¡ã¤ã³ãªãã¸ã§ã¯ãã®æä½ãå¤å®å¦çã¨ãªãã¾ãã
ã¬ã¤ã¤ã¼éã®ã«ã¼ã«ãå³æ ¼ã«ãã
決ããã«ã¼ã«ã¯ä¸è¨ã¨ãªãã¾ãã
- ã«ã¼ã«1. ã¬ã¤ã¤ã¼ãã¾ãããæ§é ä½(ã¡ã½ããã®å¼æ°ãæ»ãå¤)ã¯å
å´ã®ã¬ã¤ã¤ã¼ã«é
ç½®ãã
- æ§é ä½ã®è²¬åãææ§ã«ãªããããã¬ã¤ã¤ã¼ãè¶ ããæ§é ä½ã®å¼æ¸¡ãã¯ããªã
- æ§é ä½ã®å¤æå¦çã§ãã¤ã©ã¼ãã¬ã¼ãã¯å¤ããªããé å¼µã
- ã«ã¼ã«2. ããã±ã¼ã¸ãä¾åé¢ä¿ã®é転ã¨ãªãããã«ãã
- å¤å´ã®ã¬ã¤ã¤ã¼ãå¼ã³åºãã«ã¯èªèº«ã®ã¬ã¤ã¤ã¼ã«ã¤ã³ã¿ã¼ãã§ã¼ã¹ãé ç½®ãã¦ããããå¼ã³åºã
- ãã¡ã¤ã³ãªãã¸ã§ã¯ããé¤ãã¦å å´ã®ã¬ã¤ã¤ã¼ã®å¼ã³åºãæãinterfaceã使ç¨ãã
- ã«ã¼ã«3. çæã¡ã½ããã¯æ§é ä½ãè¿ã
ã«ã¼ã«1.ã¬ã¤ã¤ã¼ãã¾ãããæ§é ä½(ã¡ã½ããã®å¼æ°ãæ»ãå¤)ã¯å å´ã®ã¬ã¤ã¤ã¼ã«é ç½®ãã
Clean Architectureæ¬ã§ã¯ãã½ã¼ã¹ã³ã¼ãã®ä¾åæ§ã¯ãå å´(ä¸ä½ã¬ãã«ã®æ¹é)ã ãã«åãã£ã¦ããªããã°ãããªãããã¨ããæ¸ããã¦ãã¾ããã ãã®ãããã¬ã¤ã¤ã¼ãé£ã³è¶ããã¢ã¯ã»ã¹ãOKãNGãã¯ããã¼ã ã®ã«ã¼ã«ã«ãªãã¾ãã
ã¯ãªã¼ã³ã¢ã¼ããã¯ãã£ã®ãµã³ãã«ãæ¢ãã¦ã¿ãã¨ãã³ã³ããã¼ã©ã¼ãã¦ã¼ã¹ã±ã¼ã¹ãå¼ã³åºãã¦ãã¡ã¤ã³ãªãã¸ã§ã¯ããè¿ãããã¬ã¼ã³ã¿ã¼ã§å¤é¨ã®ãã¼ã¿å½¢å¼ã«å¤æãããããªãã¿ã¼ã³ãè¦åãããã¾ãã ãã®ãµã³ãã«ãã¿ã¼ã³ã許å¯ããå ´åããã¡ã¤ã³ãªãã¸ã§ã¯ããå¤é¨ã«è¿ãå¤ã¨ãã¦ä½¿ããã®ã§ããã¡ã¤ã³ãªãã¸ã§ã¯ããè³ãã¨ããã«ç»å ´ãã¦ãã¾ãã¾ããç§èªèº«ãMVCã§éçºãã¦ããæãã¢ãã«ã«Viewç¨ã®é¢æ°ã足ãã¦è²¬åãææ§ã«ãªã£ã¦ãã¾ã£ãã¨ããçµé¨ãããã¾ããã
ä»åã¯ãClean Architectureæ¬ã«ç¿ãå¶å¾¡ã®æµãã«åãã¦å¢çãè¶ ããããã«ããå¢çãè¶ ããããåãã®å¼æ°ã¨æ»ãå¤ã¯å å´ã®ã¬ã¤ã¤ã¼ã«å®ç¾©ãã¾ããã
ãã¡ãªããã¨ãã¦ãã¬ã¤ã¤ã¼ã移ããã¨ã«æ§é ä½ã®è©°æ¿ãçºçãããã¨ã«ãªãã¾ãããã¡ã«ãã¤ã§ã¯ãã¤ã¯ããµã¼ãã¹éã¯Protocol Buffersã¨gRPCã使ç¨ãã¦ãã¾ããadaptersã¬ã¤ã¤ã¼ã®å
¥åºåã¨ãã¦Protocol Buffersã®ãã¼ã«ã§çæãããæ§é ä½ã使ãã¾ããããã便å©ãªããããã®ã¾ã¾usecasesã¬ã¤ã¤ã¼ã«æ¸¡ããã¨ãèããã®ã§ãããã¬ã¤ã¤ã¼ãå³æ ¼ã«ããããå¥ã®æ§é ä½ãå®ç¾©ãããã¨ã«ãã¾ãããæ®å¿µãªãããä¼¼ããããªæ§é ä½ã®è©°ãæ¿ããçºçãã¦ãã¾ãã
ãã¡ãªãããããã¾ãããã¬ã¤ã¤ã¼ããã£ã¡ãåãããã¨ã«ããã¡ãªããã享åãã¦ããå ´æãããã¾ããããã¯ãå¥ãã¤ã¯ããµã¼ãã¹ã®Pub/Subã®ã¤ãã³ãããµãã¹ã¯ã©ã¤ããã¦ããç®æã§ãããã®ã¡ãã»ã¼ã¸ã¯æ§ã
ãªãã¤ã¯ããµã¼ãã¹ãåä¿¡ãã¦ãã¦å¤ãã®ãã£ã¼ã«ããåå¨ãã¾ããããããèªãã¤ã¯ããµã¼ãã¹ã§å¿
è¦ãªã®ã¯æ°é
ç®ã ããªã®ã§ãé¢å¿ã®ããé
ç®ã ãå®ç¾©ããæ§é ä½ãusecasesã¬ã¤ã¤ã¼ã«æ¸¡ããã¨ãåºæ¥ã¦ãã¾ãã
ã«ã¼ã«2. ããã±ã¼ã¸ãä¾åé¢ä¿ã®é転ã¨ãªãããã«ãã
æè¦çã«ããã±ã¼ã¸ã®ä¾åé¢ä¿ã®é転ãæèããã®ã¯é£ãããDIã§ããããã«ãªã£ã¦ãã¦ãããã±ã¼ã¸ã®ä¾åé¢ä¿ãé転ãã¦ããªããã¨ã¯ããããã¨æãã¦ãã¾ããç§ã®çµé¨ã§ãããScalaã§Minimal Cake Patternã使ã£ãããã¸ã§ã¯ãã§éçºãã¦ããæãå®è£ ã¨ã¤ã³ã¿ã¼ãã§ã¼ã¹ãåãããã±ã¼ã¸ã«è¨è¿°ãã¦ãããããããã±ã¼ã¸ã使ãåãã¨ãã«ä¾åé¢ä¿ãè¤éã«ãªããã³ã³ãã¤ã«æéã®å¢å ã¨ä¾åé¢ä¿ã®è¤éãã«èµ·å ããã©ã¤ãã©ãªã®ãã¼ã¸ã§ã³ã¢ãããå³ããã¨ããåé¡ã«ç´é¢ãã¾ããã(ä»ã«åé¡ããã£ãå¯è½æ§ãããã¾ãã…)
Goã§ã¯ããã¾ã§æèããå¿
è¦ã¯ç¡ããããããªãã§ãããä»åã¯ããã±ã¼ã¸ã®ä¾åé¢ä¿ã®é転ããã¡ãã¨ãã¦ã¿ããã¨æãã¾ãããã¨ã¯ãããã¤ã³ã¿ã¼ãã§ã¼ã¹ãæ¯åãå¥ããã±ã¼ã¸ã«æã§è¨è¿°ããã®ã¯é¢åã ã£ãã®ã§ãifacemakerã使ã£ã¦ã¤ã³ã¿ã¼ãã§ã¼ã¹ãçæãã¾ããããã ãifacemakerã¯åãããã±ã¼ã¸å
ã«ç½®ããã¨ãåæãªã®ã§ãå¥ããã±ã¼ã¸ã«ç½®ãã¨ä¸é¨åé¡ãããã¾ããã
åé¡ã¨ãªã£ãã±ã¼ã¹ã¯ããã¨ã®ãã¡ã¤ã«ã§ã¯ã¤ã³ãã¼ã対象ã ã£ãããã¤ã³ã¿ã¼ãã§ã¼ã¹ã«ãªãã¨ã¤ã³ãã¼ããä¸è¦ã«ãªãã±ã¼ã¹ã§ãããã¤ã¾ããã»ã«ãã¤ã³ãã¼ãã«ãªã£ã¦ãã¾ãå ´åã§ãã解決ã¯ã»ã«ãã¤ã³ãã¼ãã«ãªã£ãç®æãåé¤ããã ãã§è¯ãã£ãã®ã§ãAST解æãã¦åé¤ãããã¼ã«ãä½ãã¾ãããã¬ã¤ã¤ã¼ã«ã¼ã«ã§å
å´ã«æ§é ä½ãç½®ããã¨ã«ãããããå¼æ°ã«åºã¦ããåã¯æ¦ãæåããå¥ããã±ã¼ã¸ã¨ãªã£ã¦ãããã¨ããããããã°ã©ã ã¯è¤éãªãã®ã«ãªãã¾ããã§ããã
ã¾ããASTã®è§£æã®ã¤ãã§ã«ã¤ã³ã¿ã¼ãã§ã¼ã¹å®ç¾©ã®ä¸ã« go:generate mockgen
ã³ã¡ã³ããæ¿å
¥ãã¦åæã«ã¢ãã¯ãçæããããã«ãã¾ããã
ã«ã¼ã«3. çæã¡ã½ããã¯æ§é ä½ãè¿ã
Goã®DDDãµã³ãã«ã ã¨çæç³»(Newã§å§ã¾ããããªã¡ã½ãã)ãã¤ã³ã¿ã¼ãã§ã¼ã¹ã«å
¥ã£ã¦ããä¾ãè¦ããã¾ãããã®å ´åããã®ã¡ã½ããã¯èªèº«ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ãè¿ãå¿
è¦ãããã¾ãããããå©ç¨ãã¦å¼æ°ã§ãã©ã¤ãã¼ããªfakeæ§é ä½ãè¿ãããæ¬ç©ãè¿ãããé¸æã§ããããã«ãããã¿ã¼ã³ãããã¾ãã
ãAccept interfaces, Return structsãã¯ãã¤ã³ã¿ã¼ãã§ã¼ã¹ãåãå
¥ããæ§é ä½ãè¿ããã¨ãããã¨ã§ãããå
¬å¼wikiã®CodeReviewCommentsã«ãæ§é ä½ãå®ç¾©ãã¦ããããã±ã¼ã¸ã«ã¤ã³ã¿ã¼ãã§ã¼ã¹ãå®ç¾©ããã¹ãã§ã¯ç¡ããå©ç¨ããå´ã§ã¤ã³ã¿ã¼ãã§ã¼ã¹ãå®ç¾©ããã»ããè¯ãã¨æ¸ããã¦ãã¾ããèãæ¹çã«ã¯ã»ãã¬ã¼ãã¤ã³ã¿ã¼ãã§ã¼ã¹(PoEAA)ã«è¿ããã®ã ã¨æãã¾ããå
·è±¡åã¯ã¤ã³ã¿ã¼ãã§ã¼ã¹ãç¥ããªãã¦ãããã¨ãããã¨ãå
±éãã¦ãã¾ãã
ã¾ããGoã ã¨nil Pointer Receiverã¨ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®ç¸æ§ããã¾ãè¯ããªãã¨ãæãã¦ã¾ãã
ãã¾ãGoãããã«ãã ãã£ã¦ããããã§ã¯ç¡ãã®ã§ãããä»åãçæã¡ã½ããã¯æ§é ä½ãè¿ãããã«ãã¾ããã
æ§ã ãªå ¥åºåãçµ±ä¸çã«æ±ããããã«ãã
è¨è¨ãããã¤ã¯ããµã¼ãã¹ã®ä¸»ãªå ¥åºåã¯ä¸è¨ã¨ãªãã¾ãã
- é£æºãã¤ã¯ããµã¼ãã¹
- Google Cloud Spanner
- Google Cloud Pub/Sub
- Google Cloud Storage
- æå·åãã¼ã«
- ç°å¢å¤æ°
æ¥åãã¸ãã¯ã®ä¸ã§ä¸è¨ã®å ¥åºåãç´æ¥è¨è¿°ããã¨ãã¹ãããã«ãããªãã¾ããä¾ãã°Pub/Subã®ãµãã¹ã¯ã©ã¤ãã¼ã«ãªãã©ã¤ãã³ãã«ã¨ãã¸ãã¹ãã¸ãã¯ãæ¸ãã¦ãã¾ãã¨ããã¹ããæ¸ãã®ã大å¤ã«ãªãã¾ãã
åå ¥åºåã«å¯¾ãã¦ã¬ã¤ã¤ã¼ãæèãããã¨ã§çµ±ä¸çã«æ±ãããã¨èãã¾ãããPub/Subããã®å¦çãadaptersã¬ã¤ã¤ã¼ã¨usecasesã¬ã¤ã¤ã¼ã«åãããå¥ãã¤ã¯ããµã¼ãã¹ã®ãªã¯ã¨ã¹ããåæ§ã«ããã¨ããã«ã¼ã«ãä½ãã¾ããã
æ°¸ç¶åã³ã¼ããå³æ ¼ãªã«ã¼ã«ãé©ç¨ãã
æè¿ã ã¨æ°¸ç¶åã³ã¼ãã¯ãªãã¸ããªãã¿ã¼ã³ãé©ç¨ãããã¨ãå¤ãããã«æãã¾ããä»åãæåãªãã¸ããªãã¿ã¼ã³ã使ã£ãå¦çãæ¤è¨ãã¾ããããæ°¸ç¶åã¡ã«ããºã ã®é è½ãè¡ããã¨ã«ã¡ãªãããæããªãã£ããã¨ãadaptersã¬ã¤ã¤ã¼ã®æ»ãå¤ã¨ãã¦ãã¡ã¤ã³ãªãã¸ã§ã¯ããè¿ããã¨ã«å¯¾ããéåæãããä»åã¯ãªãã¸ããªãã¿ã¼ã³ãæ¡ç¨ãã¾ããã§ããã
æçµçã«ã¯adaptersã¬ã¤ã¤ã¼ã¯ãã¼ãã«ã²ã¼ãã¦ã§ã¤ãã¿ã¼ã³ã§æ»ãå¤ãè¿ããusescasesã¬ã¤ã¤ã¼ã§å¤æãã¦ãã¡ã¤ã³ãªãã¸ã§ã¯ãã«ããå¦çããã¼ã«æ±ºãã¾ããã
æ°¸ç¶åã¡ã«ããºã ã®é è½ã諦ããçç±
PoEAAãEvansæ¬ã¨ãã«ãªãã¸ããªãã¿ã¼ã³ã¯æ°¸ç¶åã¡ã«ããºã ãé è½ãããã¨ã«æ¯éãç½®ãã説æã¨ãªã£ã¦ãã¾ããä¸è¨ãPoEAAã®ã·ã¼ã±ã³ã¹å³ã§ã¯ã
SQLãä»æ§ãã¿ã¼ã³ã§é è½ããã¹ãã©ãã¸ã¼ãã¿ã¼ã³ã§æ°¸ç¶åã¡ã«ããºã ãé è½(åãæ¿ãå¯è½ã«)ãã¦ãã¾ããæ®åãã¦ãããªãã¸ããªãã¿ã¼ã³ã§ã¯ä»æ§ãã¿ã¼ã³ã使ããã¨ã¯å°ãªããã¨æãã¾ããPoEAAã§ãã¡ã½ããã¨ãã¦è¡¨ç¾ãã¦ããæ¹æ³ãç´å¾ã«åºã¦ãã¾ãã(ä¸è¨ã®å³ã®Criteriaãä»æ§ãã¿ã¼ã³ã§ãã)
éå»ã«æºãã£ãããã¸ã§ã¯ãã§æ°¸ç¶åã¡ã«ããºã ãCloud DataStoreããCloud Bigtableã«ç½®ãæãããã¨ãããã¾ãããæ°¸ç¶åã¡ã«ããºã ã®ç¹æ§ãçããã¨ããã¡ã¤ã³ãªãã¸ã§ã¯ããå¤ããã»ããè¯ãã¨ããçµè«ã«ãªãããã¡ã¤ã³ãªãã¸ã§ã¯ãã¯å¤æ´ã«ãªãã¾ããããã®çµé¨ãããã©ããªæ°¸ç¶åã¡ã«ããºã ã«ã対å¿ã§ãããã¡ã¤ã³ãªãã¸ã§ã¯ããè¨è¨ããã®ã¯å¹ççã§ã¯ãªãã¨èãã¾ããã
ã¾ããSpannerã®ãã©ã³ã¶ã¯ã·ã§ã³ã¯Read Only Transactionã¨Read Write Transactionãããã¾ãããã©ã³ã¶ã¯ã·ã§ã³ã¯æ°¸ç¶åã¡ã«ããºã ãã¨ã«ããªã¨ã¼ã·ã§ã³ããããçµ±ä¸åããã®ã¯é£ããã¨èãã¦ãã¾ãã
ã«ã¼ã«ãé©ç¨ããããã«ãã£ããã¨
adaptersã¬ã¤ã¤ã¼
æ°¸ç¶åã³ã¼ãå¨ãã®ã©ã¤ãã©ãªã¨ãã¦ãSpannerã®ãã¼ã¿ãã¼ã¹ããæ§é ä½ã¨ã¡ã½ãããèªåçæãã¦ãããyoã使ç¨ãã¾ããã
yoã«ãã£ã¦çæããããã¡ã¤ã«ãç´æ¥ç·¨éããã¨ã¹ãã¼ãã®å¤æ´æã«æåã§ç·¨éããªããã°ãããªãã®ã§ãçæãããæ§é ä½ãã©ããããæ§é ä½ãå®ç¾©ãã¦ãã¾ãã
yoã®ããã©ã«ãã ã¨ActiveRecordãã¿ã¼ã³ã®ããã«æ§é ä½ã¨ã¡ã½ãããä¸ç·ã«ãªãã¾ãã
ã«ã¼ã«ã«å¾ãã«ã¯ãSpannerã¯ã©ã¤ã¢ã³ãã¯driversã¬ã¤ã¤ã¼ã«ããã®ã§ãusecasesã¬ã¤ã¤ã¼ããã¢ã¯ã»ã¹ããããã«ã¯adaptersã¬ã¤ã¤ã¼ã«ã¢ã¯ã»ã¹ã¡ã½ãã(ã®æ§é ä½)ãé
ç½®ãã¦ããã¼ãã«ã®æ§é ä½ã¯usecasesã¬ã¤ã¤ã¼ã«é
ç½®ããå¿
è¦ãããã¾ãã
yoã¯ãã¼ãã«ã®æ§é ä½ã¨ã¢ã¯ã»ã¹ã¡ã½ãã(ã®æ§é ä½)ãèªåçæããæã«ãã³ãã¬ã¼ããæå®ã§ãã¾ãããã®ãã³ãã¬ã¼ãã¯ã«ã¹ã¿ãã¤ãºå¯è½ã«ãªã£ã¦ããã®ã§ãåè¿°ã®ã«ã¼ã«ã§é
ç½®ã§ããããã«ã«ã¹ã¿ãã¤ãºãã¾ããã
usecasesã¬ã¤ã¤ã¼
ä¸è¨ã®çç±ããããã¡ã¤ã³ãªãã¸ã§ã¯ãã¨ãã¼ãã«ã®æ§é ä½ãåãã¾ããã
- çµã¿è¾¼ã¿ããªã¥ã¼ãã¿ã¼ã³(PoEAA)ã使ç¨ããã
- Spanneråºæã®æ å ±(ShardIDãªã©)ã¯ãã¡ã¤ã³ãªãã¸ã§ã¯ãã«ä¿æããããªã
usecasesã¬ã¤ã¤ã¼ã®å½åã¯æåãã¼ã¿ãããã¼ã«ããã®ã§ãããæ¹ãã¦PoEAAãèªãã¨ãã¼ã¿ãããã¼ãã¿ã¼ã³ã¯
- ãã¼ãã«ã¨ãªãã¸ã§ã¯ãã®ãããã³ã°ãè¡ã
- ãªãã¸ã§ã¯ãããªã³ã¡ã¢ãªã«æã¤æã«ä¸æIDããã¼ã¨ãã¦mapã«ä¿æãã
ãããªãã¿ã¼ã³ã§ããã¨æ¸ããã¦ãã¾ãã
ãã¼ã¿ãããã¼ã®ãããã¨ã¯ã©ã£ã¡ã®æå³ã®ããããªã®ãåãããªãã£ãã®ã§ãä»åã¯ãã¼ã¿ãããã¼ã¨ããè¨èã使ãã®ãããã¾ãããã¾ããClean Architectureæ¬ã§ã¯ãã¼ãã«ã¨ãã¼ã¿æ§é ãç´ä»ãããã®ã¨ãã¦ãã¼ã¿ãããã¼ãç»å ´ãã¾ãã(ãªãã¸ã§ã¯ãã¨ç´ä»ãã¦ããã®ã§ã¯ãªãæ§é ä½ã¨ç´ä»ãã¦ããã¨ãããã¨ã強調ãã¦ãã¾ãã)
ä»åã¯ãã¼ãã«ããæ§é ä½ãçæãã¦ãçæãããæ§é ä½ããã¡ã¤ã³ãªãã¸ã§ã¯ãã«å¤æããããã«ããã®ã§ãPoEAAã¨ãClean Architectureæ¬ã¨ãç°ãªãã¨èãã¾ããã
以ä¸ã®ãã¨ãè¸ã¾ããä¸è¨ã®ããã«ãã¾ããã
- æ°¸ç¶åã¡ã«ããºã ããåå¾ã¯ã·ã³ãã«ãªãã¼ãã«ã²ã¼ãã¦ã§ã¤ãã¿ã¼ã³(PoEAA)
- usecaesã¬ã¤ã¤ã¼ã«é ç½®ããyoããçæãããæ§é ä½ãDTOã¨å½å
- DTOãããã¡ã¤ã³ãªãã¸ã§ã¯ãã«å¤æããã¦ã¼ã¹ã±ã¼ã¹ãtranslatorã¨å½å
æçµçãªã·ã¼ã±ã³ã¹å³ã¯ä¸è¨ã¨ãªãã¾ããã
å®éã¯ããå°ãè¤éã§ããtranslatorã§DTOã®æå·åããã¦ãããã£ã¼ã«ãã復å·åããå¦çãè¡ã£ã¦ãã¾ãã
ãã®æãadaptersã¬ã¤ã¤ã¼ã®æå·åãã¼ã«ã¯ã©ã¤ã¢ã³ãã«å¾©å·åãä¾é ¼ãã復å·åãããã®ãçµã¿è¾¼ã¿ããªã¥ã¼ã¨ãã¦è¡¨ç¾ãã¦ãã¾ãã
æå¾ã«
ä»å¾ã¯ãå²ã¨éåãªã¯ãªã¼ã³ã¢ã¼ããã¯ãã£ã¨ãªããã¤ã©ã¼ãã¬ã¼ããå¤ãã®ã§èªåçæã§ããã¨ããã¯èªåçæãããã¨ããã®ã¨ãä¸æ¹ã§ãæ¥åãã¸ãã¯é¨åã®æ´çãå¼±ãç®æãããã®ã§ãã¡ã¤ã³ã¬ã¤ã¤ã¼ãªã©ãå®ç¾©ãã¦æ´çãããã¨èãã¦ãã¾ãã
ææ¥ã®Merpay Advent Calendar å·çæ å½ã¯ãAML, Backendã¨ã³ã¸ãã¢ãã¼ã ã® @agro1986 ããã§ããå¼ãç¶ãã楽ãã¿ãã ããã