Thursday, May 7, 2020

TinyDocumentDB - Part 2 - The most simple API ever

So this is what I got so far. On the left side, we have a REST API with support for GET using an Id and two POST implementations.

One of the POST implementations needs an explicitly defined Id in the route, the other will use reflection to get the id from the content. At the moment, it just looks for a property named 'Id', but it should be definable later on if this is something that will stand the test of time.

The Core.Client is the coordinator at the moment for reading and writing data to some kind of storage. I've implemented two basic variants; an InMemoryReader/writer and a FileReader/Writer.


Created as a .NET Core WebApi that serves as a runtime host for the Core.Client basically.

I only handle JSON at the moment and plan to keep it that way.

The reader and the writers

The reader and writer should simply read and store data to some kind of storage as fast as possible. It should not handle caching or any hocus pocus at all. (we will get to caching later on).

  public interface IStorageReader
      Task<string> Read(string id);

  public interface IStorageWriter
      Task Write(string id, string content);
      Task Delete(string id);
To illustrate how basic this is right now, I present the Write() method of the FileStorageWriter to you:
  public async Task Write(string id, string content)
      var path = Path.Combine(FileSettings.BaseFolder, FileSettings.GenerateFileNameFromId(id));
      await System.IO.File.WriteAllTextAsync(path, content);

This code creates a path to the file by appending a base folder (hardcoded) and a filename generated from the SHA256 hash of the Id passed into the function. Then we write all the content to disk.


So achieved so far:

  • A REST API for reading and writing
  • InMemory or File-system reader writer
  • CI/CD pipeline using Github Actions

New ideas/questions:

  • How to handle schemas without making it complicated?
  • Schema stitching?
Next up:

  • Querying of data - simple indexing strategy

No comments:

Post a Comment