Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

In hindsight,  DynamoDB was a poor choice of data store for the first release of Meadowlark for two primary reasons:

  • Except for a little-known open source implementation, it is entirely restricted to Amazon Web Services.
  • The design model is interesting, but idiosyncratic.

MongoDB would have been a better starting point:

  • It is supported, directly and/or through emulation, on all major cloud platforms and on-premises.
  • It is a mature product, with strong documentation and design patterns.
  • The scalability features, such as replication and sharding, are very attractive for large implementation.

There are other NoSQL databases with similar benefits and other attractive features, such as Couchbase. However, the support is less widespread, so it will not be investigated at this time.

Although it is one of the traditional relational databases, PostgreSQL has powerful built-in support for NoSQL operations. Because of the Ed-Fi community's growing adoption of PostgreSQL, it will be explored as an alternative to MongoDB. See Meadowlark 0.2.0 - PostgreSQL.

Also see: Meadowlark 0.2.0 - Durable Change Data Capture for more information on streaming data out to OpenSearch.

Design

This proposal takes its cue from the team experience with DynamoDB. The basic principal continues that the API document is stored along with metadata to be used for existence/reference validation. However, instead of storing the metadata in columns it will be part of a single larger document. Fast document lookups continue to be done by id, constructed as before from API document project name, entity type, version and body. Transactions will again be used to check for existence/references before performing create/update/delete operations. The MongoDB version of reference validation for deletes is greatly simplified from the DynamoDB version by taking advantage of MongoDB's indexing features, in particular indexing of arrays.

Tip

To support potential deployment to Amazon DocumentDB or Azure CosmosDB, all code and design should match the MongoDB 4.0 API.

Entity Collection

The MongoDB implementation will only need one collection, to be called Entity. The shape of the Entity document (all fields required):

  • Standard attributes (also see Meadowlark - Document Shape)
    • id - A string hash derived from the project name, resource name, resource version and identity of the API document. This field will be a unique index on the collection.
    • documentIdentity - The identity elements extracted from the API document.
    • projectName -The MetaEd project name the API document resource is defined in e.g. "EdFi" for a data standard entity.
    • resourceName - The name of the resource. Typically, this is the same as the corresponding MetaEd entity name. However, there are exceptions, for example descriptors have a "Descriptor" suffix on their resource name.
    • resourceVersion - The resource version as a string. This is the same as the MetaEd project version the entity is defined in e.g. "3.3.1-b" for a 3.3b data standard entity.
    • isDescriptor - Boolean indicator.
    • edfiDoc - The Ed-Fi ODS/API document itself.
    • validated  - Boolean indicator.
    • createdBy  - name/ID of the client who created the record, for authorization usage.
  • MongoDB-specific attributes 
    • outRefs - An array of ids extracted from the ODS/API document for all externally referenced documents.
    validated  - Boolean indicator

Examples

Code Block
languagejs
titleExample: Descriptor
collapsetrue
{
    "_id" : ObjectId("6287c039abf2ff4430376b3duPvxNzlTZfnIGtMKu9K-oxLPlippk7UNmoipow"),
    "documentIdentity" : [ 
        {
            "name" : "descriptor",
            "value" : "uri://ed-fi.org/AbsenceEventCategoryDescriptor#BereavementEducationOrganizationCategoryDescriptor#Local Education Agency"
        }
    ],
    "projectName" : "Ed-Fi",
    "resourceName" : "AbsenceEventCategoryDescriptorEducationOrganizationCategory",
    "resourceVersion" : "3.3.1-b",
    "isDescriptor" : true,
    "id" : "546c96c905374bed9287409ba1ca77d28fdcd08c9d3ea3e9085d8a10",
    "edfiDoc" : {
        "codeValue" : "BereavementLocal Education Agency",
        "shortDescription" : "BereavementLocal Education Agency",
        "description" : "BereavementLocal Education Agency",
        "namespace" : "uri://ed-fi.org/AbsenceEventCategoryDescriptorEducationOrganizationCategoryDescriptor"
    },
    "existenceIds" : [ 
        "uPvxNzlTZfnIGtMKu9K-oxLPlippk7UNmoipow"
    ],
    "outRefs" : [],
    "validated" : true,
    "createdBy" : "super-great-SIS"
}

In the following example, there are two existenceId  values. You'll recognize ZAwidGBEGsnKxQ-V1ktoecnvJ8xceXjM1jMehQ as "this" document identifier. The plain text document identifier is "Ed-Fi#LocalEducationAgency#localEducationAgencyId=2231".

The second value, 0bCeilWY_p33iM0Z3wOqdI058gvNTmphi_ZBJQ, is the document Id constructed as if this document where an EducationOrganization instead of a LocalEducationAgency. Thus the plain text document identifier is "Ed-Fi#EducationOrganization#educationOrganizationId=2231"

Code Block
languagejs
titleExample: SchoolLocal Education Agency
collapsetrue
{
    "_id" : ObjectId("6287e93cabf2ff4430384af2ZAwidGBEGsnKxQ-V1ktoecnvJ8xceXjM1jMehQ"),
    "documentIdentity" : [ 
        {
            "name" : "schoolIdlocalEducationAgencyId",
            "value" : 1232231
        }
    ],
    "projectName" : "Ed-Fi",
    "resourceName" : "SchoolLocalEducationAgency",
    "resourceVersion" : "3.3.1-b",
    "isDescriptor" : false,
    "idedfiDoc" : {
        "8d111d14579c51e8aff915e7746cda7e0730ed74837af960b31c4fa6localEducationAgencyId" : 2231,
        "edfiDocnameOfInstitution" : { "Grand Bend School District",
        "schoolIdlocalEducationAgencyCategoryDescriptor" : 123"uri://ed-fi.org/LocalEducationAgencyCategoryDescriptor#Independent",
        "gradeLevelscategories" : [],
    },
    "nameOfInstitutionexistenceIds" : [ 
        "abcZAwidGBEGsnKxQ-V1ktoecnvJ8xceXjM1jMehQ", 
        "educationOrganizationCategories0bCeilWY_p33iM0Z3wOqdI058gvNTmphi_ZBJQ"
: []     }],
    "outRefs" : [],
    "validated" : true,
    "createdBy" : "super-great-SIS"
}

In the following example, note that the outRefs  array has the ID of the school from the example aboveidentifiers for a school and a student.

Code Block
languagejs
titleExample: AcademicWeekStudentInterventionAssociation, with Reference to SchoolReferences
collapsetrue
{
    "_id" : ObjectId("6287e993abf2ff4430384bfdLCEK0AxHRDUHK-5LVBlQKIarJHE83o1dVNgKWA"),
    "documentIdentity" : [ 
        {
            "name" : "schoolReferenceinterventionReference.schoolIdeducationOrganizationId",
            "value" : 123
        }, 
        {
            "name" : "interventionReference.interventionIdentificationCode",
            "value" : "111"
        }, 
        {
            "name" : "weekIdentifierstudentReference.studentUniqueId",
            "value" : "1sts0zf6d1123d3e"
        }
    ],
    "projectName" : "Ed-Fi",
    "resourceName" : "AcademicWeekStudentInterventionAssociation",
    "resourceVersion" : "3.3.1-b",
    "isDescriptor" : false,
    "idedfiDoc" : "20325050be22032deaeaddeb6a82cc160ce85911c9ad5ca8de5482e2",{
        "edfiDocstudentReference" : {
            "schoolReferencestudentUniqueId" : {"s0zf6d1123d3e"
        },
   "schoolId" : 123   "interventionReference" : {
   },         "weekIdentifierinterventionIdentificationCode" : "1st111",
            "beginDateeducationOrganizationId" : "2022-12-01", 123
        }
    },
    "endDateexistenceIds" : [ 
        "2022LCEK0AxHRDUHK-12-315LVBlQKIarJHE83o1dVNgKWA",
    ],
    "totalInstructionalDaysoutRefs" : 30[ 
   },     "outRefs" : [M42GTJNsVAGX5EOOoa7U_EwZdbOhmSiAF9wehw", 
        "8d111d14579c51e8aff915e7746cda7e0730ed74837af960b31c4fa6kKOLuEZJWjsDhpDiJOQlryLw_JBvzQ5KXTF2xg"
    ],
    "validated" : true false,
    "createdBy" : "super-great-SIS"
}


Tip

If trying to query inside of an entity, or if trying to GET ALL by type in MongoDB, then separate collections would be better than a single collection. However, when using MongoDB we would still plan to have OpenSearch or ElasticSearch in the picture for those functions. Therefore a single "table" (collection) design is appropriate, and makes sharding easy.

Insert Transaction Steps

Inserting a new Entity document into the collection will follow these steps:

  • Check that id does not exist (indexed query)
  • Check that external reference ids for the document all exist (index query per reference)
  • Perform upsert

Update Transaction Steps

Updating an existing Entity document into the collection will follow these steps:

  • Check that id exists (indexed query)
  • Check that external reference ids for the document all exist (index query per reference)
  • Perform overwrite

Delete Transaction Steps

Deleting an existing Entity document from the collection will follow these steps:

  • Check that id exists (indexed query)
  • Check that there are no out_refs for this id (indexed query)
  • Perform delete

Queries

Get all and get-by-key queries will continue to be serviced by OpenSearch. See Meadowlark 0.2.0 - Durable Change Data Capture for more information on how data will flow out to OpenSearch.

Future Considerations

Security

  • Investigate adding security annotations based on indexable API document attributes
    • Examples: ownership field, extracted education organization field
  •  Investigate using with CASL.js for attribute-based authorization

Improve version migration support

Consider ways we might want to change the id design to make migrating to newer DS versions easier. For current design, id includes project name, entity type, version, and natural key.

Let's say a new DS version comes out and a Meadowlark implementation wants to upgrade documents to the newer DS version. Assume School is unchanged between two DS versions. From the API client perspective, it would be very nice if the School resource ids didn't change. However, in the current design it would have to because version is part of the id hash.

This may get into changes in how DS versions are incorporated into resource URLs, and/or doing versions per MongoDB collection so that id is unique within a collection?

Alternative Design

An alternative design would be to create separate collections for each resource, with indexes on each queryable field. This could mean that MongoDB could serve as a single engine for all API CRUD requests, without the need for OpenSearch.

The development team has not explored this in detail at this time.


Note

This document is for discussion and general guidance. The implementation may vary as needed. The development team will endeavor to keep this document up-to-date, though working software remains a higher priority than comprehensive documentation.

Table of Contents

Table of Contents