DEV Community

Cover image for ๐—š๐˜‚๐—ถ๐—ฑ๐—ฒ #๐Ÿฌ๐Ÿฑ: ๐——๐—ฒ๐—ฒ๐—ฝ ๐—ฑ๐—ถ๐˜ƒ๐—ฒ ๐—ถ๐—ป๐˜๐—ผ ๐—ฃ๐—›๐—ฃ, ๐—”๐—ฝ๐—ฎ๐—ฐ๐—ต๐—ฒ, ๐—ฎ๐—ป๐—ฑ ๐—ฃ๐—ผ๐˜€๐˜๐—ด๐—ฟ๐—ฒ๐—ฆ๐—ค๐—Ÿ ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ
Anushka Perera
Anushka Perera

Posted on

๐—š๐˜‚๐—ถ๐—ฑ๐—ฒ #๐Ÿฌ๐Ÿฑ: ๐——๐—ฒ๐—ฒ๐—ฝ ๐—ฑ๐—ถ๐˜ƒ๐—ฒ ๐—ถ๐—ป๐˜๐—ผ ๐—ฃ๐—›๐—ฃ, ๐—”๐—ฝ๐—ฎ๐—ฐ๐—ต๐—ฒ, ๐—ฎ๐—ป๐—ฑ ๐—ฃ๐—ผ๐˜€๐˜๐—ด๐—ฟ๐—ฒ๐—ฆ๐—ค๐—Ÿ ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ

High Availability, Scaling, and Security for enterprise-level applications.
Here are my top takeaways from today's study:

๐Ÿญ. ๐—ฅ๐—ฒ๐—ฎ๐—น ๐—ฆ๐—ฒ๐—ฐ๐˜‚๐—ฟ๐—ถ๐˜๐˜† ๐—ฅ๐—ฒ๐—พ๐˜‚๐—ถ๐—ฟ๐—ฒ๐˜€ ๐—˜๐—ป๐—ณ๐—ผ๐—ฟ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜
Simply enabling ssl=on in PostgreSQL doesnโ€™t mean your connections are actually secure. To truly enforce encrypted communication between your PHP app and the database, you must update the pg_hba.conf file to use the hostssl keyword. Without this, clients can still bypass SSL and expose sensitive data.

๐Ÿฎ. ๐—ง๐—ต๐—ฒ "๐—ฃ๐—ฟ๐—ผ๐—ฐ๐—ฒ๐˜€๐˜€-๐—ฝ๐—ฒ๐—ฟ-๐—–๐—ผ๐—ป๐—ป๐—ฒ๐—ฐ๐˜๐—ถ๐—ผ๐—ป" ๐—•๐—ผ๐˜๐˜๐—น๐—ฒ๐—ป๐—ฒ๐—ฐ๐—ธ
Unlike MySQL, which uses lightweight threads, PostgreSQL creates an entirely new process for every single connection, consuming about 9 MB of memory each. If your PHP application gets a traffic spike, you will run out of memory incredibly fast. The solution? Specialized connection pooling using PgBouncer. Using transaction-level pooling allows a small handful of database connections to safely handle thousands of incoming PHP requests.

๐Ÿฏ. ๐—›๐—ถ๐—ด๐—ต ๐—”๐˜ƒ๐—ฎ๐—ถ๐—น๐—ฎ๐—ฏ๐—ถ๐—น๐—ถ๐˜๐˜† ๐—–๐—น๐˜‚๐˜€๐˜๐—ฒ๐—ฟ๐˜€
To ensure an application never goes down, we have to move beyond a single server. I looked into two different clustering models: keepalived-repmgr (same-containment) and HAProxy-PgBouncer (cross-containment). HAProxy-PgBouncer not only provides load balancing across different network zones but also improves transaction throughput by up to 9.4%.

๐Ÿฐ. ๐—›๐—ผ๐—ฟ๐—ถ๐˜‡๐—ผ๐—ป๐˜๐—ฎ๐—น ๐—ฆ๐—ฐ๐—ฎ๐—น๐—ถ๐—ป๐—ด ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ถ๐˜๐˜‚๐˜€
When vertical scaling (buying bigger servers) hits its limit, horizontal scaling is the answer. The Citus extension transforms PostgreSQL into a distributed database by sharding data across multiple worker nodes while maintaining full SQL compatibility. A major key to making this fast is "co-location"โ€”ensuring related records (like a user and their orders) live on the exact same physical node so that JOIN operations happen instantly without cross-node network calls.

hashtag#PostgreSQL hashtag#PHP hashtag#Apache hashtag#SystemArchitecture hashtag#HighAvailability hashtag#PgBouncer hashtag#WebDevelopment hashtag#Citus hashtag#DatabaseScaling

Top comments (0)