{"id":10198,"date":"2023-06-23T01:43:43","date_gmt":"2023-06-23T08:43:43","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/document-optimizations\/"},"modified":"2023-06-23T01:43:43","modified_gmt":"2023-06-23T08:43:43","slug":"document-optimizations","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/","title":{"rendered":"Document Optimizations"},"content":{"rendered":"<p class=\"wp-block-paragraph\">JSON gives us a flexible schema, that allows our models to rapidly adapt to change, this is because the schema is explicitly stored alongside each value.  Whereas, in an RDBMS the schema is defined by the table columns, which are defined once.  In any database, every byte of stored data adds up, historically this has been abstracted from developers as the schema and the database are managed by a DBA.  With an application enforced schema, the model size is now controlled by the application.  As developers we tend to be overly verbose when describing variables throughout our applications, this practice tends to carry over to our JSON models.   While it is generally preferred to maintain human-readable field names for developer productivity, there are often well-understood abbreviations for many fields that will not reduce document readability.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a general approach, consider the following options to proactively reduce document sizes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Don&#8217;t store the document ID as a repeated value in the document<\/li>\n\n\n<li>Convert ISO-8601 timestamps to epoch time in milliseconds, saving at least 11 bytes. When millisecond precision is not required, convert to a smaller value (i.e. divide by 1000 to convert to seconds, 60 for minutes, 60 for hours, 24 for days), saving at least 4 bytes<\/li>\n\n\n<li>Store dates as an ISO format <code>YYYY-MM-DD<\/code> instead of <code>MMM DD, YYYY<\/code><\/li>\n\n\n<li>When using GUID&#8217;s strip all dashes saving an additional 4 bytes per GUID<\/li>\n\n\n<li>Use shorter property names<\/li>\n\n\n<li>Don&#8217;t store properties whose value is <code>null<\/code> , empty <code>String|Array|Object<\/code>, or a known default<\/li>\n\n\n<li>Don&#8217;t repeat values in arrays whose value is not unique, use a top-level property on the document<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-storing-dates\" class=\"wp-block-heading\">Storing Dates<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It is very common in almost any application, there is a need to store a date.  This could be when the document was created, modified, when an order was placed, etc.  Generally, this date is stored in <a href=\"https:\/\/www.iso.org\/iso-8601-date-and-time-format.html\">ISO-8601<\/a> format.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Take the date <code>2018-12-14T03:45:24.478Z<\/code> as an example, this is very <em>readable<\/em>, but is it the most efficient way to store the date?  Storing this same date as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Unix_time\">Unix Epoch Time<\/a> we can represent this same date as <code>1544759124478<\/code>.  ISO-8601 is 24 bytes, where epoch format is 13 bytes, this saves 11 bytes.  This might not seem like a lot, but consider this scenario: 500,000,000 documents and each document has an average of 2 date properties.  If we used epoch format, we&#8217;d save 11,000,000,000 bytes or 11Gb of space.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, take this a step further and ask the question, &#8220;What level of precision does the application require?&#8221;.  Often times we do not need millisecond precision, we can divide the epoch date accordingly for seconds, minutes, hours, etc.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table>\n<thead>\n<tr>\n<th align=\"left\"><strong>Epoch Date<\/strong><\/th>\n<th align=\"left\"><strong>Precision<\/strong><\/th>\n<th align=\"left\"><strong>Reduction<\/strong><\/th>\n<th align=\"left\"><strong>Output<\/strong><\/th>\n<th align=\"left\"><strong>Length \/ Bytes<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\">1544759124478<\/td>\n<td align=\"left\">milliseconds<\/td>\n<td align=\"left\"><code>n\/a<\/code><\/td>\n<td align=\"left\">1544759124478<\/td>\n<td align=\"left\">13<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">1544759124478<\/td>\n<td align=\"left\">seconds<\/td>\n<td align=\"left\"><code>\/ 1000<\/code><\/td>\n<td align=\"left\">1544759124<\/td>\n<td align=\"left\">10<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">1544759124478<\/td>\n<td align=\"left\">minutes<\/td>\n<td align=\"left\"><code>\/1000 \/ 60<\/code><\/td>\n<td align=\"left\">25745985<\/td>\n<td align=\"left\">8<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">1544759124478<\/td>\n<td align=\"left\">hours<\/td>\n<td align=\"left\"><code>\/1000 \/ 60 \/ 60<\/code><\/td>\n<td align=\"left\">429099<\/td>\n<td align=\"left\">6<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">1544759124478<\/td>\n<td align=\"left\">days<\/td>\n<td align=\"left\"><code>\/1000 \/ 60 \/ 60 \/ 24<\/code><\/td>\n<td align=\"left\">17879<\/td>\n<td align=\"left\">5<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/figure>\n\n\n\n<h3 id=\"h-embedded-vs--nonembedded-data\" class=\"wp-block-heading\">Embedded vs. Non-Embedded Data<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Typically denormalized document models provide better read performance<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Embed when there are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Relationship between entities<\/li>\n\n\n<li>One-to-few relationships between entities<\/li>\n\n\n<li>Embedded data that will not grow unbounded<\/li>\n\n\n<li>Embedded data that is integral to data in a document<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Do not embed and normalize when there are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Unbounded data\/arrays<\/li>\n\n\n<li>Frequent change of data across models<\/li>\n\n\n<li>Unrelated models<\/li>\n\n\n<li>One-to-many relationships<\/li>\n\n\n<li>Many-to-many relationships<\/li>\n\n\n<li>Frequent changes to related data<\/li>\n\n\n<li>Referenced data could be unbounded<\/li>\n\n\n<li>Smaller mutations are required for replication\/network performance<\/li>\n\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>JSON gives us a flexible schema, that allows our models to rapidly adapt to change, this is because the schema is explicitly stored alongside each value. Whereas, in an RDBMS the schema is defined by the table columns, which are defined once. In any database, every byte of stored data adds up, historically this has [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"tutorial-languages":[551],"tutorial-tags":[566,565],"tutorial-technologies":[562,548,554],"tutorial-types":[555],"class_list":["post-10198","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-any","tutorial-tags-best-practices","tutorial-tags-data-modeling","tutorial-technologies-capella","tutorial-technologies-kv","tutorial-technologies-server","tutorial-types-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Document Optimizations - Couchbase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Document Optimizations\" \/>\n<meta property=\"og:description\" content=\"JSON gives us a flexible schema, that allows our models to rapidly adapt to change, this is because the schema is explicitly stored alongside each value. Whereas, in an RDBMS the schema is defined by the table columns, which are defined once. In any database, every byte of stored data adds up, historically this has [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/\" \/>\n<meta property=\"og:site_name\" content=\"Couchbase\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Couchbase\/\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2548\" \/>\n\t<meta property=\"og:image:height\" content=\"1171\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@couchbase\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-optimizations\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-optimizations\\\/\",\"name\":\"Document Optimizations - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#website\"},\"datePublished\":\"2023-06-23T08:43:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-optimizations\\\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-optimizations\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-optimizations\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Document Optimizations\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"width\":1129,\"height\":1129,\"caption\":\"Couchbase\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Couchbase\\\/\",\"https:\\\/\\\/x.com\\\/couchbase\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/CouchbaseServer\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/couchbase\\\/\",\"https:\\\/\\\/github.com\\\/couchbase\\\/\",\"https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Couchbase,_Inc.\"],\"description\":\"Couchbase is a database software company headquartered in San Jose, California, providing an operational data platform for AI used by hundreds of global enterprises.\",\"legalName\":\"Couchbase, Inc.\",\"foundingDate\":\"2011-01-01\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Document Optimizations - Couchbase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/","og_locale":"de_DE","og_type":"article","og_title":"Document Optimizations","og_description":"JSON gives us a flexible schema, that allows our models to rapidly adapt to change, this is because the schema is explicitly stored alongside each value. Whereas, in an RDBMS the schema is defined by the table columns, which are defined once. In any database, every byte of stored data adds up, historically this has [&hellip;]","og_url":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/","og_site_name":"Couchbase","article_publisher":"https:\/\/www.facebook.com\/Couchbase\/","og_image":[{"width":2548,"height":1171,"url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@couchbase","twitter_misc":{"Est. reading time":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/","url":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/","name":"Document Optimizations - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/de\/#website"},"datePublished":"2023-06-23T08:43:43+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-optimizations\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/"},{"@type":"ListItem","position":2,"name":"Document Optimizations"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/de\/#website","url":"https:\/\/www.couchbase.com\/de\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/de\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/de\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/de\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/de\/","logo":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.couchbase.com\/de\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","contentUrl":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","width":1129,"height":1129,"caption":"Couchbase"},"image":{"@id":"https:\/\/www.couchbase.com\/de\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Couchbase\/","https:\/\/x.com\/couchbase","https:\/\/www.youtube.com\/c\/CouchbaseServer","https:\/\/www.linkedin.com\/company\/couchbase\/","https:\/\/github.com\/couchbase\/","https:\/\/en.wikipedia.org\/wiki\/Couchbase,_Inc."],"description":"Couchbase ist ein in San Jose, Kalifornien, ans\u00e4ssiges Unternehmen f\u00fcr Datenbanksoftware, das eine operative Datenplattform f\u00fcr KI bereitstellt, die von Hunderten von globalen Unternehmen eingesetzt wird.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials\/10198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials\/10198\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/media?parent=10198"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-languages?post=10198"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-tags?post=10198"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-technologies?post=10198"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-types?post=10198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}