GitLab के Postgres स्कीमा डिज़ाइन पर मेरे नोट्स (2022)
(shekhargulati.com)GitLab Postgres स्कीमा डिज़ाइन पर मेरे नोट्स
- GitLab के Postgres स्कीमा को देखकर, अपनी डिज़ाइन की तुलना करना और GitLab की schema definitions से best practices सीखना।
- GitLab एक ओपन-सोर्स DevOps प्लेटफ़ॉर्म है, GitHub का विकल्प और self-hosting के लिए उपलब्ध है।
सही Primary Key प्रकार का उपयोग
- जब डेटाबेस छोटा होता है तब यह बड़ा मुद्दा नहीं लगता, लेकिन स्केल बढ़ने पर primary key storage space, write speed और read speed को प्रभावित कर सकता है।
- GitLab के पास 573 tables हैं: इनमें से 380 tables में
bigserialprimary key type है, 170 मेंserial4, और बाकी 23 में composite primary key है।
Internal और External ID का उपयोग
- अपनी internal primary key को बाहर expose न करना अच्छा practice है।
- GitLab
issues,ci_pipelines,deployments,epicsजैसी tables में internal ID (id) और external ID (iid) दोनों का उपयोग करता है।
text data type और CHECK constraint का उपयोग
- GitLab schema में
character varying(n)औरtextदोनों हैं, लेकिनtextका उपयोग ज्यादा है। textमें length limit नहीं होती, इसलिए लंबाई की सीमाएँCHECKconstraints से define की जाती हैं।
Naming conventions
- सभी tables plural form में हैं और namespace देने के लिए module prefix use किया गया है।
- table और column नाम snake_case format का पालन करते हैं।
Timestamp में time zone का उपयोग
- GitLab दोनों उपयोग करता है:
timestamp with timezoneऔरtimestamp without timezone। - सिस्टम operations के लिए
timestamp without timezoneऔर user actions के लिएtimestamp with timezoneuse होते हैं।
Foreign key constraints
- GitLab अधिकांश tables में foreign key constraints use करता है, लेकिन
audit_events,abuse_reports,web_hooks_logs,spam_logsजैसी कुछ tables में नहीं।
बड़े tables की partitioning
- GitLab query performance सुधारने के लिए बड़े हो सकने वाले tables को partition करता है।
Trigrams और gin_trgm_ops के साथ LIKE search use cases को support करना
- GitLab efficient खोज के लिए GIN (Generalized Inverted Index) index का उपयोग करता है।
jsonb का उपयोग
- GitLab schema कई tables में
jsonbडेटा type का उपयोग करता है।
अन्य tips
- बदलने योग्य tables में
updated_atजैसी audit fields रखी जाती हैं, जबकि immutable log tables में नहीं। - Enums को
character varyingके बजायsmallintमें store करके space बचाया जाता है।
GN⁺ की राय:
- GitLab का स्कीमा डिज़ाइन DB design के लिए अच्छे insights देता है और बड़े पैमाने पर चलने वाले systems के लिए schema optimization पर महत्वपूर्ण lessons देता है।
- GitLab ओपन-सोर्स होने की वजह से, ये schema design निर्णय अन्य developers के लिए practical examples बनते हैं जिन्हें अपने projects में apply किया जा सकता है।
- GitLab schema से सीख मिलती है कि datatype चुनना, indexing strategy, partitioning और foreign key constraints का सही उपयोग जैसे decisions सीधे DB performance और maintainability को प्रभावित करते हैं।
1 टिप्पणियां
Hacker News टिप्पणियाँ
CI_PIPELINE_IIDऔरCI_MERGE_REQUEST_IIDमें अतिरिक्त "I" क्यों जोड़ा गया, इस पर जिज्ञासा जताई गई और यह समझ आया कि यह शायद database design से जुड़ा फैसला था, जिसकी पुष्टि लेख में मिलती है।