This pull request implements fine-grained traits for the products::store port.
Current situation
The current implementation uses a single trait for products::store::Store, which is then stored in a Box<dyn Store> in a products::CrudService. Because of that, all Lambda functions behind API Gateway have references to all the functions implemented by the Store trait.
By running make build && grep 'Scanning DynamoDB table' build/*/bootstrap on the current main branch, I get the following results:
That means that whenever there is a code change for the all() function for DynamoDBStore, all four Lambda functions will be updated.
New implementation
By running the same command, I only get a single match from the Lambda functions, meaning that the other ones no longer have code for functions that will never be called.
Binary file build/get-products/bootstrap matches
I can confirm that functions are the same by comparing the hash of all binaries after a small code change on products::store::dynamodb::DynamoDBStore's implementation of all() (using sha256sum build/*/bootstrap after a make build).
The only hash that changed is for build/get-products/bootstrap, as expected. Meaning that functions won't redeploy unless there is a code change that affected them.
As part of this change, I've also moved the domain logic layer to src/domain.rs. It's currently just functions until I implement a better interface, for example using extension traits.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
This pull request implements fine-grained traits for the
products::store
port.Current situation
The current implementation uses a single trait for
products::store::Store
, which is then stored in aBox<dyn Store>
in aproducts::CrudService
. Because of that, all Lambda functions behind API Gateway have references to all the functions implemented by theStore
trait.By running
make build && grep 'Scanning DynamoDB table' build/*/bootstrap
on the current main branch, I get the following results:That means that whenever there is a code change for the
all()
function for DynamoDBStore, all four Lambda functions will be updated.New implementation
By running the same command, I only get a single match from the Lambda functions, meaning that the other ones no longer have code for functions that will never be called.
I can confirm that functions are the same by comparing the hash of all binaries after a small code change on
products::store::dynamodb::DynamoDBStore
's implementation ofall()
(usingsha256sum build/*/bootstrap
after amake build
).Before:
After:
The only hash that changed is for
build/get-products/bootstrap
, as expected. Meaning that functions won't redeploy unless there is a code change that affected them.As part of this change, I've also moved the domain logic layer to
src/domain.rs
. It's currently just functions until I implement a better interface, for example using extension traits.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.