Sitemap

Start new project?

Monolithic or Microservice

--

Monolithic (โปรเจค)

  • โปรเจคที่มี tiered เดียว เช่น window application, web application ซึ่งจะรวม feature ทั้งหมดอยู่ในโปรเจคเดียวกัน ซึ่งมี user interface และ data access ที่ผูกติดกับการโปรแกรมด้วย 1 platform เท่านั่น

— ตัวอย่าง platform ที่ใช้ใน Monolith เช่น ASP.net, JSP.net, J2EE … etc

  • Functional ทั้งหมดจะมีการเชื่อมต่อกันใน 1 application
  • กระบวนการทำงานของ Monolithic จะใช้ Waterfall model กัน จะมีขั้นตอนการทำงาน ดั้งนี้

— เก็บ Requirement -> จะได้เอกสาร 1 ชุดเพื่อทำการยืนยันว่า application จะต้องมีการทำงานตามเอกสารนี้นะ product requirements document (SRS)

— ออกแบบ application -> ในส่วนนี้จะได้ตัวอย่างหรือ mockup application และเอาไปให้ user ดูและยืนยันอีกที ซึ่งก็จะมีไอเดียบรรเจิดมากในช่วงนี้ และจะมีการแก้ไข เพิ่มเติม หลังจากยืนยันเอกสารก่อนหน้านี้ ก็ต้องปรับ แก้ ตัวอย่างหลายรอบอยู่กว่าจะไปขั้นตอนต่อไปได้

— Implement -> โปรแกรมหรือ Code application ทั้งหมดตามที่ได้ทำตัวอย่าง ให้ user ดู แล้วเอกสาร (SRS) ละ ก็ไม่ได้อัพเดทไง เลยอ้างอิงไม่ได้ มาดูชีวิต Dev กัน

— — หา DB, Web App, IDE มาติดตั้งในเครื่อง เพื่อจะเริ่ม Code

— — Configuration each software (App server, Database … etc)

— — ออกแบบ DB ด้วย เพราะ SA บอกให้ทำมาก่อน แล้วจะดูให้

— ตรวจสอบ -> ก็จะมี 3 ส่วนที่ทำการตรวจสอบ

  1. Dev จะทำการตรวจสอบเองก่อนทั้งหมด ซึ่งจะทดสอบเท่าที่ตัวเองคิด และบางทีไม่ทำ unit test ด้วย ซึ่งก็รู้ๆกันอยู่ว่าต้องมี bug แน่นอน แต่จะส่งงานไม่ทันแล้ว
  2. Tester จะทำการทดสอบตาม scenario testcase ทั้งหมด ซึ่งก็ต้องให้ Dev ช่วยส่งผลบางอัน และแก้ไข bug ไปด้วย
  3. User (UAT) ทดสอบก่อนรับมอบงาน

— Maintenance -> Software + new bugs

  • Overview Monolithic
M

Microservices

  • Microservices เกิดมาเพื่อการพัฒนา software ให้ง่านและไวขึ้น (จริงเหรอ?)
  • โดยแยกส่วน feature และ services ออกมาเป็น โปรเจคย่อยๆ
  • แต่ละ microservice จะทำงารเพื่อการบริการสิ่งเดียวกัน และสามารถไปเชื่อต่อ microservices อื่นๆ ได้ด้วย
  • แต่ระบบจะถูกกระจายการทำงานได้ และเพิ่มประสิทธิภาพของ production
  • Microservices จะเชื่อต่อกันด้วย APIs.
  • ส่วน infra ของระบบ เดียวนี้จะหันมาใช้ Software container (Docker) เพื่อแยกและ deploy software ได้ง่ายขึ้น
  • กระบวนการทำงานของ Microservices จะเป็นแบบ Agile team

— Requirement ->Backlog

— Design + Implement + Verification -> Software

Get Surachai Samatasribut’s stories in your inbox

Join Medium for free to get updates from this writer.

— Demo -> Improve or New requirement

  • Overview
Press enter or click to view image in full size
M and M

จุดเด่น microservices

  • Different technologies and languages
  • Easy to integrate and scale with third-party applications.
  • Microservices can be deployed (prod) as needed
  • ทดลอง solution ใหม่ๆได้เลย
  • ค่าดูแลจะไม่แพง
  • ถ้ามีงานที่ใช้service เดิม ก็แค่ duplication service ขึ้นมาได้เลย โดยไม่ต้องทำงานเริ่มใหม่ตั้งแต่แรก
  • ง่ายในการต่อยอดในแต่ละ service โดยไม่กระทบส่วนอื่นของระบบ

จุดด้วย

  • ระบบการเทสจะยุ่งยากหน่อย ๆ ๆ ๆ หลายหน่อยก็เยอะ
  • จะต้องมีการจำกัดจำนวนของ service ด้วย จำนวน service ยิ่งมาก ยิ่งจัดการยาก
  • ต้องการนักพัฒนาที่มีชั่วโมงบินสูง
  • จำเป็นต้องมีการ crontrol version แต่ละ service
  • แอบแพง

Mono vs. Micro

Press enter or click to view image in full size

Example

E-commerce

  • Requirement -> ขายส้มน้ำผึ้งบนหน้าเว็บไซต์ โดยชำระเงินด้วยบัตรเครดิด
  • Design ->
  1. Website (Frontent)
  2. Database (Customer, Products, Order, Stock, Payment)
  3. Business logic (API)
  4. Payment gateway
  • Implement -> Web, API(customer), API (Product), API (Order) …
  • Testing -> unit test, automate test, api test
  • Deploy

Summery

ถ้าทุนน้อย เวลาจำกัด และ จะทำเลย ก็ monolithic ไป หรือ small app ก็ monolithec

สำหรับองค์กรขนาดใหญ่ Microservices are like departments within a company; each department has its own role, its own specific set of skills. Following in this same analogy, APIs are like those employees with expertise in a number of different areas. DDD

--

--