System Design¶
Data Flow Architecture¶
Tileverse allows applications to stream tiled data from remote storage directly to the client (or processing engine) with minimal memory overhead.
1. Request Lifecycle¶
When a PMTilesReader requests a tile (z, x, y):
- Spatial Index Lookup: The reader calculates the Hilbert ID for the requested tile.
- Directory Fetch: It checks if the relevant directory section is in memory. If not, it issues a byte-range request to the
RangeReader. - Offset Calculation: Using the directory data, it finds the exact byte offset and length of the tile data in the archive.
- Data Fetch: It issues a second byte-range request to the
RangeReaderfor the actual tile body, exposed to callers as a streamingInputStream. - Optional Decoding:
PMTilesReader.getTile(...)itself just returns the raw bytes. Higher-level wrappers run a decoder against the same stream:PMTilesVectorTileStorefeeds it toVectorTileCodecto produce aVectorTile;PMTilesRasterTileStorefeeds it tojavax.imageio.ImageIOto produce aRenderedImage. Decoding the tile body never materializes an intermediateByteBufferbecause the streamingIOFunction<InputStream, D>overload runs the mapper directly on the channel-backed stream.
2. Caching Strategy¶
To avoid network latency, the CachingRangeReader implements a two-tier cache:
- Tier 1 (Metadata): PMTiles directories and headers are highly cacheable and small. They are prioritized in the "Meta" cache.
- Tier 2 (Data): Actual tile data is cached in a separate "Data" cache (optional), useful for hot areas of the map.
3. Extensibility¶
The system is designed for extension via interfaces:
- Implement
StorageProvider(registered viaServiceLoader) to add an in-scope storage backend - for example, a new S3-compatible service that does not advertisex-amz-*headers, an internal CAS-style store, or a test harness. Native protocols like OpenStack Swift, Azure Files (SMB), or HDFS-via-WebHDFS are intentionally out of scope; see Why tileverse-storage?. - Subclass
AbstractTileStore<T>to expose a different archive format under the sameTileStore<T>contract (for example, Versatiles or MBTiles). - Implement
TileMatrixSetto support non-Earth or custom grids while reusing the rest of the stack unchanged.