အဓိက အကြောင်းအရာသို့ ကျော်သွားရန်
OpenAI

၂၀၂၆ ဇန်နဝါရီ ၂၂

အင်ဂျင်နီယာနယ်ပယ်

ChatGPT အသုံးပြုသူ သန်း 800 ကို ပံ့ပိုးရန် PostgreSQL ကို ချဲ့ထွင်ခြင်း

နည်းပညာဝန်ထမ်းအဖွဲ့ဝင် Bohan Zhang ရေးသားသည်

ဖွင့်နေသည်…

နှစ်ပေါင်းများစွာအတွင်း PostgreSQL သည် ChatGPT နှင့် OpenAI ၏ API ကဲ့သို့သော အဓိကထုတ်ကုန်များကို အခြေခံမှ ပံ့ပိုးပေးနေသည့် အရေးကြီးဆုံး ဒေတာစနစ်များထဲမှ တစ်ခုဖြစ်ခဲ့သည်။ ကျွန်ုပ်တို့၏ အသုံးပြုသူအရေအတွက် မြန်ဆန်စွာ ကြီးထွားလာသလို database များအပေါ်ရှိ လိုအပ်ချက်များလည်း အဆတိုးလာခဲ့သည်။ ပြီးခဲ့သည့် တစ်နှစ်အတွင်း PostgreSQL load သည် 10 ဆကျော် တိုးလာခဲ့ပြီး ယခုလည်း ဆက်လက် မြန်မြန်တိုးနေသည်။

ဤတိုးတက်မှုကို ထိန်းထားနိုင်ရန် production infrastructure ကို တိုးမြှင့်ပြင်ဆင်ခဲ့ရာမှ အမြင်သစ်တစ်ခု ရရှိခဲ့သည်။ လူများစွာ ယခင်က ထင်ထားသည်ထက် PostgreSQL ကို read-heavy workload အလွန်ကြီးမားသည့် အခြေအနေများအတွက် ယုံကြည်စိတ်ချစွာ ချဲ့ထွင်နိုင်သည်။ ဤစနစ်ကို မူလက University of California, Berkeley ရှိ သိပ္ပံပညာရှင်အဖွဲ့တစ်ဖွဲ့က ဖန်တီးခဲ့ပြီး၊ global region များစွာအနှံ့ ဖြန့်ကျက်ထားသော read replica 50 နီးပါးနှင့် primary တစ်ခုတည်းသော Azure PostgreSQL flexible server instance(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) ဖြင့် ကမ္ဘာလုံးဆိုင်ရာ traffic အကြီးအကျယ်ကို ပံ့ပိုးနိုင်စေခဲ့သည်။ ဤသည်မှာ OpenAI တွင် PostgreSQL ကို တင်းကျပ်သော optimization များနှင့် ခိုင်မာသော engineering ဖြင့် အသုံးပြုသူ သန်း 800 အတွက် တစ်စက္ကန့်လျှင် query သန်းများကို ပံ့ပိုးနိုင်အောင် မည်သို့ ချဲ့ထွင်ခဲ့သနည်းဆိုသည့် ဇာတ်လမ်းဖြစ်ပြီး လမ်းတစ်လျှောက် လေ့လာရရှိခဲ့သည့် အဓိကသင်ခန်းစာများကိုလည်း ဖော်ပြသွားမည်ဖြစ်သည်။

မူလဒီဇိုင်း၏ အက်ကွဲရာများ

ChatGPT ကို မိတ်ဆက်ပြီးနောက် traffic သည် မကြုံစဖူး မြန်နှုန်းဖြင့် တိုးလာခဲ့သည်။ ၎င်းကို ပံ့ပိုးရန် application နှင့် PostgreSQL database layer နှစ်ခုစလုံးတွင် optimization အများအပြားကို အလျင်အမြန် လုပ်ဆောင်ခဲ့ပြီး၊ instance size ကို တိုးခြင်းဖြင့် scale up လုပ်ကာ read replica များ ထပ်ထည့်ခြင်းဖြင့် scale out လုပ်ခဲ့သည်။ ဤ architecture သည် ကျွန်ုပ်တို့ကို အချိန်ကြာမြင့်စွာ ကောင်းစွာ ပံ့ပိုးပေးခဲ့သည်။ ဆက်လက်တိုးတက်မှုများနှင့်အတူ အနာဂတ်ကြီးထွားမှုအတွက်လည်း လုံလောက်သော runway ကို ဆက်လက် ပေးနေသည်။

single-primary architecture တစ်ခုတည်းက OpenAI အရွယ်အစား၏ လိုအပ်ချက်များကို ဖြည့်ဆည်းနိုင်သည်ဆိုခြင်းမှာ အံ့အားသင့်ဖွယ် ဖြစ်နိုင်သော်လည်း အကောင်အထည်ဖော်ရာတွင် မလွယ်ကူပါ။ Postgres overload ကြောင့် ဖြစ်ပွားသော SEV အချို့ကို ကျွန်ုပ်တို့ တွေ့ခဲ့ရပြီး ၎င်းတို့သည် မကြာခဏ ပုံစံတူတစ်မျိုးကို လိုက်နာလေ့ရှိသည်။ upstream issue တစ်ခုက database load ကို ရုတ်တရက် မြင့်တက်စေသည်။ ဥပမာ caching layer ပျက်ကွက်မှုကြောင့် cache miss များ အများအပြား ဖြစ်ပွားခြင်း၊ စရိတ်ကြီး multi-way join များက CPU ကို ပြည့်နှက်စေခြင်း၊ သို့မဟုတ် feature အသစ် မိတ်ဆက်မှုကြောင့် write storm ဖြစ်ပေါ်ခြင်းတို့ ဖြစ်သည်။ resource utilization မြင့်လာသည်နှင့်အမျှ query latency မြင့်တက်လာပြီး request များ timeout ဖြစ်လာသည်။ ထို့နောက် retry များက load ကို ထပ်မံ ချဲ့ထွင်ကာ ChatGPT နှင့် API service တစ်ခုလုံးကို ထိခိုက်ပျက်စီးစေနိုင်သော ဆိုးဝါးသံသရာတစ်ခုကို ဖြစ်စေသည်။

ဝန်တိုးချဲ့မှု ပုံကြမ်း

PostgreSQL သည် ကျွန်ုပ်တို့၏ read-heavy workload များအတွက် ကောင်းစွာ scale လုပ်နိုင်သော်လည်း write traffic မြင့်မားသည့် ကာလများတွင် စိန်ခေါ်မှုများကို ရင်ဆိုင်နေရဆဲ ဖြစ်သည်။ ၎င်းမှာ အဓိကအားဖြင့် PostgreSQL ၏ multiversion concurrency control (MVCC) implementation ကြောင့် ဖြစ်ပြီး write-heavy workload များအတွက် ထိရောက်မှု နည်းစေသည်။ ဥပမာ query တစ်ခုက tuple တစ်ခု သို့မဟုတ် field တစ်ခုတည်းကိုပင် update လုပ်လျှင် row တစ်ကြောင်းလုံးကို copy လုပ်ကာ version အသစ် ဖန်တီးရသည်။ write load ကြီးမားသည့် အခြေအနေတွင် ၎င်းသည် write amplification ကို သိသိသာသာ ဖြစ်စေသည်။ ထို့အပြင် query များသည် နောက်ဆုံး version ကို ရယူရန် tuple version များစွာ (dead tuple များ) ကို scan လုပ်ရသောကြောင့် read amplification ကိုလည်း တိုးစေသည်။ MVCC သည် table နှင့် index bloat၊ index maintenance overhead တိုးလာခြင်းနှင့် ရှုပ်ထွေးသည့် autovacuum tuning ကဲ့သို့သော စိန်ခေါ်မှုများကိုလည်း ဖြစ်စေသည်။ (ဤအကြောင်းများကို Carnegie Mellon University မှ Prof. Andy Pavlo နှင့်အတူ ရေးသားခဲ့သော PostgreSQL ၏ ကျွန်ုပ်တို့ အမုန်းဆုံး အပိုင်း(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) ဟူသော blog တွင် နက်နက်ရှိုင်းရှိုင်း ဖတ်ရှုနိုင်ပြီး PostgreSQL Wikipedia စာမျက်နှာတွင်လည်း ကိုးကား(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) ထားသည်။)

PostgreSQL ကို QPS သန်းများအထိ ချဲ့ထွင်ခြင်း

ဤကန့်သတ်ချက်များကို လျော့ချပြီး write pressure ကို လျှော့ချရန် shard လုပ်နိုင်သော workload များ (အလျားလိုက် partition ခွဲနိုင်သော workload များ) နှင့် write-heavy workload များကို Azure Cosmos DB ကဲ့သို့ sharded system များသို့ ကျွန်ုပ်တို့ ပြောင်းရွှေ့ပြီးဖြစ်သလို ဆက်လက် ပြောင်းရွှေ့လျက်လည်း ရှိသည်။ ထို့ပြင် မလိုအပ်သော write များကို လျှော့ချရန် application logic ကိုလည်း optimize လုပ်ထားသည်။ လက်ရှိ PostgreSQL deployment ထဲသို့ table အသစ်များ ထည့်သွင်းခွင့်ကိုလည်း မပေးတော့ပါ။ workload အသစ်များကို ပုံမှန်အားဖြင့် sharded system များသို့ သတ်မှတ်ထားသည်။

infrastructure တိုးတက်ပြောင်းလဲလာသော်လည်း PostgreSQL ကို shard မလုပ်ဘဲ write အားလုံးကို primary instance တစ်ခုတည်းက ဆောင်ရွက်နေဆဲ ဖြစ်သည်။ အဓိကအကြောင်းရင်းမှာ လက်ရှိ application workload များကို shard လုပ်ခြင်းသည် အလွန် ရှုပ်ထွေးပြီး အချိန်ကုန်မည်ဖြစ်ကာ application endpoint ရာနှင့်ချီကို ပြောင်းလဲရမည်ဖြစ်ပြီး လပေါင်းများစွာ သို့မဟုတ် နှစ်ပေါင်းများစွာတိုင်နိုင်သောကြောင့် ဖြစ်သည်။ ကျွန်ုပ်တို့၏ workload များမှာ အဓိကအားဖြင့် read-heavy ဖြစ်ပြီး optimization အများအပြား ပြုလုပ်ပြီးဖြစ်သည့်အတွက် လက်ရှိ architecture သည် ဆက်လက် traffic ကြီးထွားမှုကို ပံ့ပိုးရန် လုံလောက်သော headroom ကို ပေးနေဆဲဖြစ်သည်။ အနာဂတ်တွင် PostgreSQL ကို shard လုပ်ခြင်းကို မပယ်ဖျက်ထားသော်လည်း လက်ရှိနှင့် အနာဂတ်ကြီးထွားမှုအတွက် runway လုံလောက်သဖြင့် ၎င်းသည် နီးစပ်သည့် အချိန်ကာလ ဦးစားပေးမဟုတ်ပါ။

အောက်ပါအပိုင်းများတွင် PostgreSQL ကို ၎င်း၏ ကန့်သတ်ချက်များအထိ တွန်းပို့ကာ တစ်စက္ကန့်လျှင် query သန်းများ (QPS) အထိ ချဲ့ထွင်နိုင်ရန် ကျွန်ုပ်တို့ ရင်ဆိုင်ခဲ့သည့် စိန်ခေါ်မှုများနှင့် ၎င်းတို့ကို ဖြေရှင်းပြီး အနာဂတ် outage များကို ကာကွယ်ရန် လုပ်ဆောင်ခဲ့သည့် optimization အများအပြားကို နက်နက်ရှိုင်းရှိုင်း ရှင်းလင်းသွားမည်ဖြစ်သည်။

primary ပေါ်ရှိ load ကို လျှော့ချခြင်း

စိန်ခေါ်မှု - writer တစ်ခုတည်းသာ ရှိသောကြောင့် single-primary setup သည် write များကို scale မလုပ်နိုင်ပါ။ write spike များ ပြင်းထန်လာပါက primary ကို အလွန်လျင်မြန်စွာ overload ဖြစ်စေနိုင်ပြီး ChatGPT နှင့် ကျွန်ုပ်တို့၏ API ကဲ့သို့သော service များကို ထိခိုက်စေနိုင်သည်။

ဖြေရှင်းချက် - write spike များကို ကိုင်တွယ်ရန် လုံလောက်သော capacity ရှိနေစေရန် primary ပေါ်ရှိ load ကို read နှင့် write နှစ်မျိုးစလုံးမှ အတတ်နိုင်ဆုံး လျှော့ချသည်။ read traffic ကို ဖြစ်နိုင်သမျှ replica များသို့ offload လုပ်သည်။ သို့သော် read query အချို့သည် write transaction များ၏ အစိတ်အပိုင်းဖြစ်သောကြောင့် primary ပေါ်တွင်ပင် ဆက်ရှိရမည်။ ထို query များအတွက် ထိရောက်မှုရှိစေရန်နှင့် slow query မဖြစ်စေရန် အာရုံစိုက်သည်။ write traffic အတွက် shard လုပ်နိုင်ပြီး write-heavy ဖြစ်သော workload များကို Azure CosmosDB ကဲ့သို့ sharded system များသို့ ပြောင်းရွှေ့ထားသည်။ shard လုပ်ရန် ပိုခက်ခဲသော်လည်း write volume မြင့်မားနေသေးသော workload များကို ပြောင်းရွှေ့ရန် ပိုကြာပြီး ထိုလုပ်ငန်းစဉ်မှာ ယခုထိ ဆက်လက်လုပ်ဆောင်နေဆဲ ဖြစ်သည်။ ထို့အပြင် application များကို ပြင်းပြင်းထန်ထန် optimize လုပ်ကာ write load ကို လျှော့ချခဲ့သည်။ ဥပမာ redundant write များ ဖြစ်စေသော application bug များကို ပြင်ဆင်ခဲ့ပြီး သင့်လျော်သည့်နေရာများတွင် lazy write များကို ထည့်သွင်းကာ traffic spike များကို ချောမွေ့စေခဲ့သည်။ ထို့ပြင် table field များ backfill လုပ်ရာတွင် write pressure အလွန်အကျွံ မဖြစ်စေရန် တင်းကျပ်သော rate limit များကို သတ်မှတ်ထားသည်။

Query optimization

စိန်ခေါ်မှု - PostgreSQL တွင် စရိတ်ကြီး query အချို့ကို ကျွန်ုပ်တို့ ခွဲခြားတွေ့ရှိခဲ့သည်။ ယခင်က ဤ query များ၏ volume ရုတ်တရက် တိုးလာသောအခါ CPU အရင်းအမြစ် အများအပြားကို စားသုံးပြီး ChatGPT နှင့် API request နှစ်မျိုးစလုံးကို နှေးကွေးစေခဲ့သည်။

ဖြေရှင်းချက် - table အများအပြားကို join လုပ်သော စရိတ်ကြီး query အနည်းငယ်ကပင် service တစ်ခုလုံး၏ စွမ်းဆောင်ရည်ကို သိသိသာသာ ကျဆင်းစေခြင်း သို့မဟုတ် လုံးဝ ပြုတ်ကျစေခြင်း ဖြစ်နိုင်သည်။ ထို့ကြောင့် PostgreSQL query များကို ထိရောက်မှုရှိစေရန်နှင့် Online Transaction Processing (OLTP) anti-pattern များကို ရှောင်ရှားနိုင်စေရန် ဆက်တိုက် optimize လုပ်နေရန် လိုအပ်သည်။ ဥပမာ တစ်ခါက table 12 ခုကို join လုပ်သော အလွန်စရိတ်ကြီး query တစ်ခုကို ကျွန်ုပ်တို့ တွေ့ရှိခဲ့ပြီး ထို query spike များသည် ယခင် high-severity SEV များ၏ အဓိကအကြောင်းရင်း ဖြစ်ခဲ့သည်။ ဖြစ်နိုင်သမျှ ရှုပ်ထွေးသော multi-table join များကို ရှောင်ရှားသင့်သည်။ join များ လိုအပ်ပါက query ကို အပိုင်းပိုင်း ခွဲကာ ရှုပ်ထွေးသော join logic ကို application layer သို့ ရွှေ့ရန် စဉ်းစားသင့်ကြောင်း သင်ယူရရှိခဲ့သည်။ ဤပြဿနာရှိ query အများအပြားကို Object-Relational Mapping framework (ORM) များက generate လုပ်သောကြောင့် ၎င်းတို့ ထုတ်လုပ်သည့် SQL ကို ဂရုတစိုက် ပြန်လည်သုံးသပ်ပြီး မျှော်လင့်ထားသလို လုပ်ဆောင်နေကြောင်း သေချာစေရန် အရေးကြီးသည်။ PostgreSQL တွင် အချိန်ကြာရှည် idle ဖြစ်နေသော query များကိုလည်း မကြာခဏ တွေ့ရသည်။ idle_in_transaction_session_timeout ကဲ့သို့သော timeout များကို configure လုပ်ခြင်းသည် ၎င်းတို့ autovacuum ကို ပိတ်ဆို့မထားစေရန် အလွန်အရေးကြီးသည်။

Single point of failure ကို လျှော့ချခြင်း

စိန်ခေါ်မှု - read replica တစ်ခု down ဖြစ်ပါက traffic ကို အခြား replica များသို့ ဆက်လက် လမ်းကြောင်းပြောင်းပေးနိုင်သည်။ သို့သော် writer တစ်ခုတည်းကိုသာ အားထားရခြင်းသည် single point of failure တစ်ခု ရှိနေခြင်းဖြစ်ပြီး ၎င်း down ဖြစ်ပါက service တစ်ခုလုံး ထိခိုက်မည်ဖြစ်သည်။

ဖြေရှင်းချက် - အရေးကြီးဆုံး request အများစုတွင် read query များသာ ပါဝင်သည်။ primary ၏ single point of failure ကို လျော့ချရန် ထို read များကို writer ထံမှ replica များသို့ offload လုပ်ခဲ့ပြီး primary down ဖြစ်သော်လည်း ထို request များ ဆက်လက် service ပေးနိုင်စေရန် သေချာစေခဲ့သည်။ write operation များ မအောင်မြင်သေးနိုင်သော်လည်း ထိခိုက်မှုမှာ လျော့နည်းသွားသည်။ read များ ဆက်လက် ရနိုင်နေသောကြောင့် SEV0 မဟုတ်တော့ပါ။

primary failure များကို လျှော့ချရန် primary ကို High-Availability (HA) mode ဖြင့် hot standby တစ်ခုနှင့်အတူ run လုပ်ထားသည်။ ၎င်းသည် အမြဲတမ်း synchronise လုပ်ထားသော replica တစ်ခုဖြစ်ပြီး traffic ကို ချက်ချင်း လွှဲပြောင်းယူရန် အမြဲအဆင်သင့်ရှိသည်။ primary down ဖြစ်သည့်အခါ သို့မဟုတ် maintenance အတွက် offline လုပ်ရန်လိုသည့်အခါ downtime ကို လျှော့ချရန် standby ကို အလျင်အမြန် promote လုပ်နိုင်သည်။ Azure PostgreSQL အဖွဲ့သည် load အလွန်မြင့်မားသည့် အခြေအနေများတွင်ပင် failover များ လုံခြုံယုံကြည်စိတ်ချစွာ ဆက်လက် လုပ်ဆောင်နိုင်စေရန် အလုပ်အများအပြား လုပ်ဆောင်ထားသည်။ read replica failure များကို ကိုင်တွယ်ရန် region တစ်ခုစီတွင် capacity headroom လုံလောက်စွာရှိသော replica အများအပြားကို deploy လုပ်ထားပြီး replica တစ်ခုတည်း ပျက်ကွက်မှုကြောင့် region တစ်ခုလုံး outage မဖြစ်စေရန် သေချာစေထားသည်။

Workload isolation

စိန်ခေါ်မှု - PostgreSQL instance များပေါ်တွင် request အချို့က အရင်းအမြစ် အလွန်အကျွံ စားသုံးသည့် အခြေအနေများကို မကြာခဏ ကြုံတွေ့ရသည်။ ၎င်းကြောင့် တူညီသော instance များပေါ်တွင် လုပ်ဆောင်နေသော အခြား workload များ၏ စွမ်းဆောင်ရည် ကျဆင်းနိုင်သည်။ ဥပမာ feature အသစ် မိတ်ဆက်ခြင်းကြောင့် PostgreSQL CPU ကို အလွန်အသုံးပြုသည့် မထိရောက်သော query များ ပေါ်လာနိုင်ပြီး အခြား အရေးကြီး feature များ၏ request များကို နှေးကွေးစေနိုင်သည်။

Solution: To mitigate the “noisy neighbor” problem, we isolate workloads onto dedicated instances to ensure that sudden spikes in resource-intensive requests don’t impact other traffic. Specifically, we split requests into low-priority and high-priority tiers and route them to separate instances. This way, even if a low-priority workload becomes resource-intensive, it won’t degrade the performance of high-priority requests. We apply the same strategy across different products and services as well, so that activity from one product does not affect the performance or reliability of another.

Connection pooling

Challenge: Each instance has a maximum connection limit (5,000 in Azure PostgreSQL). It’s easy to run out of connections or accumulate too many idle ones. We’ve previously had incidents caused by connection storms that exhausted all available connections.

Solution: We deployed PgBouncer as a proxy layer to pool database connections. Running it in statement or transaction pooling mode allows us to efficiently reuse connections, greatly reducing the number of active client connections. This also cuts connection setup latency: in our benchmarks, the average connection time dropped from 50 milliseconds (ms) to 5 ms. Inter-region connections and requests can be expensive, so we co-locate the proxy, clients, and replicas in the same region to minimize network overhead and connection use time. Moreover, PgBouncer must be configured carefully. Settings like idle timeouts are critical to prevent connection exhaustion.

PostgreSQL ပရောက်စီ ပုံကြမ်း

read replica တစ်ခုချင်းစီတွင် PgBouncer pod အများအပြားကို chạy နေသော ကိုယ်ပိုင် Kubernetes deployment ရှိသည်။ တူညီသော Kubernetes Service ၏နောက်ကွယ်တွင် Kubernetes deployment အများအပြားကို ကျွန်ုပ်တို့ run လုပ်ပြီး pod များအနှံ့ traffic ကို load-balance လုပ်ပါသည်။

Caching

Challenge: A sudden spike in cache misses can trigger a surge of reads on the PostgreSQL database, saturating CPU and slowing user requests.

Solution: To reduce read pressure on PostgreSQL, we use a caching layer to serve most of the read traffic. However, when cache hit rates drop unexpectedly, the burst of cache misses can push a large volume of requests directly to PostgreSQL. This sudden increase in database reads consumes significant resources, slowing down the service. To prevent overload during cache-miss storms, we implement a cache locking (and leasing) mechanism so that only a single reader that misses on a particular key fetches the data from PostgreSQL. When multiple requests miss on the same cache key, only one request acquires the lock and proceeds to retrieve the data and repopulate the cache. All other requests wait for the cache to be updated rather than all hitting PostgreSQL at once. This significantly reduces redundant database reads and protects the system from cascading load spikes.

Scaling read replicas

Challenge: The primary streams Write Ahead Log (WAL) data to every read replica. As the number of replicas increases, the primary must ship WAL to more instances, increasing pressure on both network bandwidth and CPU. This causes higher and more unstable replica lag, which makes the system harder to scale reliably.

Solution: We operate nearly 50 read replicas across multiple geographic regions to minimize latency. However, with the current architecture, the primary must stream WAL to every replica. Although it currently scales well with very large instance types and high-network bandwidth, we can’t keep adding replicas indefinitely without eventually overloading the primary. To address this, we’re collaborating with the Azure PostgreSQL team on cascading replication(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်), where intermediate replicas relay WAL to downstream replicas. This approach allows us to scale to potentially over a hundred replicas without overwhelming the primary. However, it also introduces additional operational complexity, particularly around failover management. The feature is still in testing; we’ll ensure it’s robust and can fail over safely before rolling it out to production.

PostgreSQL cascading replication ပုံကြမ်း

Rate limit

Challenge: A sudden traffic spike on specific endpoints, a surge of expensive queries, or a retry storm can quickly exhaust critical resources such as CPU, I/O, and connections, which causes widespread service degradation.

Solution: We implemented rate-limiting across multiple layers—application, connection pooler, proxy, and query—to prevent sudden traffic spikes from overwhelming database instances and triggering cascading failures. It’s also crucial to avoid overly short retry intervals, which can trigger retry storms. We also enhanced the ORM layer to support rate limiting and when necessary, fully block specific query digests. This targeted form of load shedding enables rapid recovery from sudden surges of expensive queries.

Schema Management

Challenge: Even a small schema change, such as altering a column type, can trigger a full table rewrite(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်). We therefore apply schema changes cautiously—limiting them to lightweight operations and avoiding any that rewrite entire tables.

Solution: Only lightweight schema changes are permitted, such as adding or removing certain columns that do not trigger a full table rewrite. We enforce a strict 5-second timeout on schema changes. Creating and dropping indexes concurrently is allowed. Schema changes are restricted to existing tables. If a new feature requires additional tables, they must be in alternative sharded systems such as Azure CosmosDB rather than PostgreSQL. When backfilling a table field, we apply strict rate limits to prevent write spikes. Although this process can sometimes take over a week, it ensures stability and avoids any production impact.

Results and the road ahead

This effort demonstrates that with the right design and optimizations, Azure PostgreSQL can be scaled to handle the largest production workloads. PostgreSQL handles millions of QPS for read-heavy workloads, powering OpenAI’s most critical products like ChatGPT and the API platform. We added nearly 50 read replicas, while keeping replication lag near zero, maintained low-latency reads across geo-distributed regions, and built sufficient capacity headroom to support future growth.

This scaling works while still minimizing latency and improving reliability. We consistently deliver low double-digit millisecond p99 client-side latency and five-nines availability in production. And over the past 12 months, we’ve had only one SEV-0 PostgreSQL incident (it occurred during the viral launch(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) of ChatGPT ImageGen, when write traffic suddenly surged by more than 10x as over 100 million new users signed up within a week.)

While we’re happy with how far PostgreSQL has taken us, we continue to push its limits to ensure we have sufficient runway for future growth. We’ve already migrated the shardable write-heavy workloads to our sharded systems like CosmosDB. The remaining write-heavy workloads are more challenging to shard—we’re actively migrating those as well to further offload writes from the PostgreSQL primary. We’re also working with Azure to enable cascading replication so we can safely scale to significantly more read replicas.

Looking ahead, we’ll continue to explore additional approaches to further scale, including sharded PostgreSQL or alternative distributed systems, as our infrastructure demands continue to grow.

စာရေးသူ

Bohan Zhang

ကျေးဇူးတင်လွှာ

ဤပို့စ်တွင် ပါဝင်ကူညီခဲ့သော Jon Lee၊ Sicheng Liu၊ Chaomin Yu နှင့် Chenglong Hao တို့အပြင် PostgreSQL ကို ချဲ့ထွင်ရာတွင် ကူညီခဲ့သော အဖွဲ့တစ်ခုလုံးကို အထူးကျေးဇူးတင်ရှိပါသည်။ ခိုင်မာသော ပူးပေါင်းဆောင်ရွက်မှုအတွက် Azure PostgreSQL အဖွဲ့ကိုလည်း ကျေးဇူးတင်ရှိပါသည်။