Introduction to chiitiler: Serverless Raster Tile Server

Kanahiro Iguchi - Nov 3 - - Dev Community

Raster Tile Server needs server!

There are some implementations for raster tile server - MapServer, TileserverGL...
To launch, those servers need persisted server instance like AWS EC2 or Fargate.

These runtimes are great but have limitation on scaling and need more manual settings, comparing to AWS Lambda. In tile server, many requests occur at simultaneously and it is better to run on runtime more scalable like Lambda.

chiitiler: Serverless Tile Server

https://github.com/Kanahiro/chiitiler

My implementation "chiitiler" is designed to be able to run on AWS Lambda. Lambda Web Adapter enables for container images to run on Lambda and chiitiler utilizes it. Following is demo on AWS Lambda.

https://spatialty-io.github.io/chiitiler-demo/

Usage

You can use container image.

# most simple settings
docker run -p 3000:3000 -d \
-e CHIITILER_CACHE_METHOD=memory \
-e CHIITILER_DEBUG=true \
ghcr.io/kanahiro/chiitiler
# running server: http://localhost:3000

# example: use s3cache
docker run -p 3000:3000 -d \
-e CHIITILER_CACHE_METHOD=s3 \
-e CHIITILER_S3CACHE_BUCKET=bucketname \
-e CHIITILER_S3_REGION=ap-northeast-1 \
ghcr.io/kanahiro/chiitiler
# running server: http://localhost:3000
# debug page: http://localhost:3000/debug
Enter fullscreen mode Exit fullscreen mode

Key concept of chiitiler

The key concept of chiitiler is "input: MapLibre Style, output: Raster Tile".

Traditional raster tile servers like TileserverGL define map styles at launching and defnitions like MapFile or style.json are stored in the server.

On the otherhand, I have used TiTiler for serving Cloud Optimized GeoTIFF(COG).

https://developmentseed.org/titiler/

This server accepts "url of COG" and respond raster tiles. This interface that content of tile is defined on request time has much flexibility than servers with pre-defined styles.

Referencing this, I defined interface of chiitiler like this:

http://localhost:3000/tiles/0/0/0.png?url=https://tile.openstreetmap.jp/styles/osm-bright/style.json
# you can pass stylejson via request-body in POST-method
Enter fullscreen mode Exit fullscreen mode

On each request, chiitiler loads style.json and retrieve assets like tiles, sprites, glyphs. This interface provides great flexibilty for clients! Besides, this means chiitiler doesn't depends on file system and then it is easy to run on serverless runtimes.

Of course, this implementation has "penalty" in performance because data fetching is needed before rendering tile but have mecahnism to compensate this.

Protocols

Protocols chiitiler supports:

  • http://
  • https://
  • s3://
  • file://
  • mbtiles://
  • pmtiles://
  • cog:// (experimental)

These can be used in source in style.json. There are no other expansion to Style Specification. You can write stylejson like following, this is cool.

{
  "version": "8",
  "sources": {
    "dir": {
      "type": "vector",
      "tiles": [
        "file://localdata/tiles/{z}/{x}/{y}.pbf"
      ],
      "maxzoom": 6
    },
    "mbtiles": {
      "type": "vector",
      "tiles": [
        "mbtiles://localdata/school.mbtiles/{z}/{x}/{y}"
      ],
      "maxzoom": 10
    },
    "pmtiles": {
      "type": "vector",
      "tiles": [
        "pmtiles://localdata/school.pmtiles/{z}/{x}/{y}"
      ],
      "maxzoom": 10
    },
    "s3": {
      "type": "vector",
      "tiles": [
        "s3://tiles/{z}/{x}/{y}.pbf"
      ],
      "maxzoom": 6
    },
    "cog": {
      "type": "raster",
      "tiles": [
        "cog://https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/54/T/WN/2024/9/S2A_54TWN_20240908_0_L2A/TCI.tif/{z}/{x}/{y}"
      ],
      "tileSize": 256
    }
  },
  "layers": []
}
Enter fullscreen mode Exit fullscreen mode

Architecture and features

Image descriptionArchitecture of chiitiler

Support AWS S3

chiitiler designed to nicely run on AWS Lambda with supporting AWS S3 as datasource. The latency between Lambda and S3 is so small that the "penalty" to retrieve assets on each request become reasonable. This is more useful by combining PMTiles with S3.

File Caching

When retrieve assets not from AWS S3, you can cache them in the method you defined: Filesystem, Memory, AWS S3 and None. I strongly recommend AWS S3 with the reason I've already explaned above.

This caching is very important on performance because many assets are needed to render one tile and many of them are repeatedly needed to render another. The demo retrieves assets from japan.openstreetmap.jp and cache them to AWS S3.

Image descriptiononly few hundred milliseconds are needed to dynamically render tiles

On the otherhand, rendered tile cache is not implemented and there is no plan to do because it is better that rendered tiles are cached by CDN.

Conclusion

chiitiler enables you launch raster tile server on AWS Lambda - serverless runtime. Lambda has great scalability and it is very important in tileserver which accepts many requests. Please use chiitiler and feedback me your thoughts!

. . . .
Terabox Video Player