[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-th-1-1-all-websocket-scaling-redis-kubernetes-all--*":3,"academy-blog-translations-1idpw9dwit26mgw":105},{"data":4,"page":92,"perPage":92,"totalItems":92,"totalPages":92},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":100,"keywords":101,"locale":74,"published_at":102,"scheduled_at":13,"school_blog":96,"short_description":103,"status":94,"title":6,"updated":104,"updated_by":13,"slug":97,"views":99},"EP.39 การขยายระบบ WebSocket ด้วย Redis และ Kubernetes","sclblg987654321","school_blog_translations","\u003Ch3 data-pm-slice=\"1 1 []\">\u003Cspan>\u003Cstrong>ทำไมต้องขยายขนาด WebSocket?\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fh3>\u003Cp>\u003Cspan>WebSocket เป็นเทคโนโลยีที่ใช้ในการรับส่งข้อมูลแบบเรียลไทม์ แต่เมื่อจำนวนผู้ใช้เพิ่มขึ้น \u003Cstrong>โหลดของเซิร์ฟเวอร์อาจสูงขึ้นจนระบบไม่สามารถรองรับได้\u003C\u002Fstrong> วิธีการแก้ปัญหาคือการใช้ \u003Cstrong>Redis Pub\u002FSub และ Kubernetes\u003C\u002Fstrong> เพื่อขยายขีดความสามารถของระบบ\u003C\u002Fspan>\u003C\u002Fp>\u003Ch3>\u003Cspan>\u003Cstrong>โครงสร้างของระบบที่รองรับการขยายขนาด\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fh3>\u003Col data-spread=\"false\">\u003Cli>\u003Cspan>\u003Cstrong>Client\u003C\u002Fstrong> - ผู้ใช้งานที่เชื่อมต่อ WebSocket\u003C\u002Fspan>\u003C\u002Fli>\u003Cli>\u003Cspan>\u003Cstrong>Load Balancer\u003C\u002Fstrong> - กระจายโหลดไปยังหลาย WebSocket Servers\u003C\u002Fspan>\u003C\u002Fli>\u003Cli>\u003Cspan>\u003Cstrong>WebSocket Servers\u003C\u002Fstrong> - จัดการการเชื่อมต่อและส่งข้อมูลแบบเรียลไทม์\u003C\u002Fspan>\u003C\u002Fli>\u003Cli>\u003Cspan>\u003Cstrong>Redis Pub\u002FSub\u003C\u002Fstrong> - ทำหน้าที่กระจายข้อมูลระหว่าง WebSocket Servers\u003C\u002Fspan>\u003C\u002Fli>\u003Cli>\u003Cspan>\u003Cstrong>Kubernetes Cluster\u003C\u002Fstrong> - บริหารจัดการเซิร์ฟเวอร์หลายตัวโดยอัตโนมัติ\u003C\u002Fspan>\u003C\u002Fli>\u003C\u002Fol>\u003Ch3>\u003Cspan>\u003Cstrong>ใช้ Redis Pub\u002FSub เพื่อเชื่อมต่อ WebSocket หลายเครื่อง\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fh3>\u003Cp>\u003Cspan>Redis Pub\u002FSub ช่วยให้ WebSocket Servers หลายตัวสามารถรับ-ส่งข้อความให้กันได้\u003C\u002Fspan>\u003C\u002Fp>\u003Ch4>\u003Cspan>\u003Cstrong>ตัวอย่างการใช้งาน Redis Pub\u002FSub กับ WebSocket\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fh4>\u003Cp>\u003Cspan>ไฟล์ \u003C\u002Fspan>\u003Ccode>\u003Cspan>websocket_redis.go\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">package main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n    \"github.com\u002Fgo-redis\u002Fredis\u002Fv8\"\n)\n\nvar ctx = context.Background()\n\nfunc main() {\n    client := redis.NewClient(&amp;redis.Options{\n        Addr: \"localhost:6379\",\n    })\n\n    pubsub := client.Subscribe(ctx, \"chat_channel\")\n    defer pubsub.Close()\n\n    for msg := range pubsub.Channel() {\n        fmt.Println(\"Received message:\", msg.Payload)\n    }\n}\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3 data-pm-slice=\"1 1 []\">\u003Cspan>\u003Cstrong>การใช้ Kubernetes เพื่อขยาย WebSocket Servers\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fh3>\u003Cp>\u003Cspan>เราสามารถใช้ \u003Cstrong>Kubernetes Deployment\u003C\u002Fstrong> เพื่อจัดการ WebSocket Servers หลายเครื่องให้สามารถทำงานร่วมกันได้\u003C\u002Fspan>\u003C\u002Fp>\u003Ch4>\u003Cspan>\u003Cstrong>ไฟล์ \u003C\u002Fstrong>\u003C\u002Fspan>\u003Ccode>\u003Cspan>\u003Cstrong>deployment.yaml\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan>\u003Cstrong> สำหรับ Kubernetes\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fh4>\u003Cpre>\u003Ccode class=\"language-plaintext\">apiVersion: apps\u002Fv1\nkind: Deployment\nmetadata:\n  name: websocket-server\nspec:\n  replicas: 3\n  selector:\n    matchLabels:\n      app: websocket-server\n  template:\n    metadata:\n      labels:\n        app: websocket-server\n    spec:\n      containers:\n      - name: websocket-server\n        image: my-websocket-server:latest\n        ports:\n        - containerPort: 8080\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3 data-pm-slice=\"1 1 []\">\u003Cspan>\u003Cstrong>ท้าให้ลอง!\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fh3>\u003Cp>\u003Cspan>ลองปรับแต่ง \u003Cstrong>Kubernetes Horizontal Pod Autoscaler (HPA)\u003C\u002Fstrong> เพื่อให้ระบบสามารถเพิ่มหรือลดจำนวน WebSocket Servers ตามโหลดของผู้ใช้โดยอัตโนมัติ!\u003C\u002Fspan>\u003C\u002Fp>\u003Chr>\u003Ch3>\u003Cspan>\u003Cstrong>EP ถัดไป\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fh3>\u003Cp>\u003Cspan>ใน \u003Cstrong>EP.40\u003C\u002Fstrong> เราจะมาดู \u003Cstrong>การใช้ GraphQL Subscription ร่วมกับ WebSocket ใน Kubernetes\u003C\u002Fstrong> เพื่อเพิ่มประสิทธิภาพของ API แบบเรียลไทม์ 🚀\u003C\u002Fspan>\u003C\u002Fp>","49_11zon_kqn9miy906.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fwtxa0ha74atq366\u002F49_11zon_kqn9miy906.webp","2026-03-04 08:51:12.061Z","",{"keywords":15,"locale":68,"school_blog":78},[16,23,28,33,38,43,48,53,58,63],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:44:32.154Z","u0s66bjop3dljau","Horizontal Scaling","2026-04-10 16:12:46.399Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:44:32.713Z","b9jmymu9lbpj60c","High Availability","2026-04-10 16:12:46.701Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:44:29.876Z","ozn15duk6wovj6g","Microservices","2026-04-10 16:12:46.024Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:51:09.083Z","qnfn648h0o2s90l","Real-Time API","2026-04-10 16:14:33.342Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:20:14.253Z","ah6lvy4x8qe08l5","Golang","2026-04-10 16:07:26.172Z",{"collectionId":17,"collectionName":18,"created":44,"created_by":13,"id":45,"name":46,"updated":47,"updated_by":13},"2026-03-04 08:20:11.547Z","ey3puyme01a9bsw","Go","2026-04-10 16:07:25.893Z",{"collectionId":17,"collectionName":18,"created":49,"created_by":13,"id":50,"name":51,"updated":52,"updated_by":13},"2026-03-04 08:34:10.799Z","m3qoswhgnc4c38n","Kubernetes","2026-04-10 16:08:08.875Z",{"collectionId":17,"collectionName":18,"created":54,"created_by":13,"id":55,"name":56,"updated":57,"updated_by":13},"2026-03-04 08:34:10.254Z","rss87kgvhtvkri1","Redis Pub\u002FSub","2026-04-10 16:08:08.714Z",{"collectionId":17,"collectionName":18,"created":59,"created_by":13,"id":60,"name":61,"updated":62,"updated_by":13},"2026-03-04 08:48:01.322Z","qwms9vhmllldxj2","WebSocket Load Balancing","2026-04-10 16:13:38.951Z",{"collectionId":17,"collectionName":18,"created":64,"created_by":13,"id":65,"name":66,"updated":67,"updated_by":13},"2026-03-04 08:44:50.258Z","nrtw5001po78dez","WebSocket Scaling","2026-04-10 16:12:50.756Z",{"code":69,"collectionId":70,"collectionName":71,"created":72,"flag":73,"id":74,"is_default":75,"label":76,"updated":77},"th","pbc_1989393366","locales","2026-01-22 10:59:55.832Z","twemoji:flag-thailand","s8wri3bt4vgg2ji",true,"Thai","2026-04-10 15:42:46.614Z",{"category":79,"collectionId":80,"collectionName":81,"created":13,"expand":82,"id":96,"slug":97,"updated":98,"views":99},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs",{"category":83},{"blogIds":84,"collectionId":85,"collectionName":86,"created":87,"created_by":13,"id":79,"image":88,"image_alt":13,"image_path":89,"label":90,"name":91,"priority":92,"publish_at":93,"scheduled_at":13,"status":94,"updated":95,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:33:53.210Z","59ty92ns80w_15oc1implw.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fwqxt7ag2gn7xcmk\u002F59ty92ns80w_15oc1implw.png",{"en":91,"th":91},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","1idpw9dwit26mgw","websocket-scaling-redis-kubernetes","2026-05-07 18:52:13.131Z",311,"wtxa0ha74atq366",[20,25,30,35,40,45,50,55,60,65],"2025-03-17 02:13:16.338Z","เรียนรู้วิธี ขยายขีดความสามารถของ WebSocket โดยใช้ Redis Pub\u002FSub และ Kubernetes เพื่อรองรับการใช้งานที่มีผู้ใช้จำนวนมาก และปรับปรุงประสิทธิภาพของระบบแบบเรียลไทม์","2026-04-22 07:11:44.721Z",{"th":97,"en":97}]