# AssetBundle Ledger
Is a manifest that holds information about a set of bundle names and bundle version that needs to be downloaded in order to function properly. There will be multiple versions of ledgers over the life of an app. Each time ledger version is udpated (remote side), it means there is a new ledger available i.e. there may be new bundles to download.
Note* Ledger version can be downgraded incase there are issues with a new content rollout. The client will revert and resume as normal.
## Client/Shared
### Ledger Service (Internal)
A ledger service will check the remote side periodically if there is any change in the ledger version and queries for the latest ledger if there is a new version. All bundles cached locally will be suffixed with their version, eg.```"country_flags_v12.unity3d"``` to identify them individually. It will check ledger bundle versions with locally available cache, if needed it will download missing bundles from cdn.
Once all the bundle dependencies for the new ledger are met, it will swap out the
currently active ledger. Based on the active ledger, correct (version resolved) local bundle path can be queried using normal bundle path.
eg ```GetBundlePath("xyz\country_flag")``` will return ```xyz\country_flag_v12.unity3d```
Note* this service and its apis are completely abstracted from front-end devs.
#### Cache Purge
In case there is not enough space for new download it will purge the cache of all the bundles, excepted new ledger dep and current ledger dep (as fallback incase the new ledger fails to download or there is still insufficient space).
Note* The ledger file will contain info about individual bundle sizes so total space required can be computed before download.
### BaseAssetLoader (Public API)
Whenever BaseAssetLoader.LoadAssetBundle() is called ( or some other new api if needed). It will query Ledger Service for the resolved bundle path and return the correct asset bundle object, that the front-end dev can use to access the required asset.
## Server Side
App can periodically make rest calls for the latest ledger version.
Response Ex.
```json
{
// This will change anytime there is an update in the ledger
"ledger_version": "$REMOTE_LEDGER_VERSION",
// Useful to know if app supports the data structure.
// App might need to updated if it is not supported
"required_data_structure_version": "$DATA_STRUCT_VERSION"
}
```
We can query for the ledger using the version.
Response Ex.
```json
{
// Dictionary with bundles and versions needed
// by this ledger to function properly
"latest_bundle_version": [{ "$BUNDLE_NAME": "$BUNDLE_VERSION" }],
"bundle_size": [{ "$BUNDLE_NAME": "$FILE_SIZE" }],
}
```
# Game Side
Frontend devs can bundle content prefabs that may need to change (e.g. ui main_menu) and push it up to cdn, along with the latest ledger cms update. Load the content from the bundle at runtime. Whenever we need to change the ui eg, christmas season main menu ui update, we push a new bundle with the changes and update the ledger. It will automatically reflect once all the ledger dependencies are resolved.