python services · validation · observability
Charles Trinh — FastAPI Service Layer, Las Vegas NV

Building the service layer behind a clinical API: schema-first validation, dependency injection for auth, structured logging, and failure semantics a caller can act on.
Schema-first, always
Define request and response models before handlers; the model is the contract and the documentation is generated from it.
Pydantic validation at the boundary rejects malformed input before it reaches business logic, which turns a class of runtime errors into a 422 with a reason.
Version the models explicitly rather than mutating them in place, because a caller three months behind is a caller you still serve.
Authorization in the dependency graph
Auth belongs in dependencies that resolve identity, scope and tenant, injected into the handler rather than checked inside it.
The check must receive the same objects the query uses; a dependency that computes a patient ID the handler then ignores is decoration.
Log the decision with its inputs, because an authorisation you cannot replay is one you cannot defend.
Structured logging and correlation
One correlation ID per request, propagated to every downstream call, with the patient identifier hashed rather than logged in the clear.
Log the decision points, not the payloads; payload logging is how PHI ends up in a log aggregator.
Make the log schema stable, because dashboards and alerts break when field names drift.
Failure semantics
Distinguish invalid input, unauthorised, not found, dependency failure and timeout in both status code and body.
A caller that receives a generic 400 has no behaviour available to it and will retry into an outage.
Return a machine-readable reason alongside the human message, and keep the human message free of internal detail.
Health, readiness and shutdown
Separate liveness from readiness; a service that reports live while its database is unreachable produces confident failures.
Drain connections on shutdown, because a rolling deploy that drops in-flight clinical writes is worse than a slow one.
Expose the version in the health payload, so an incident call can establish what is actually running.
Performance and back-pressure
Bound concurrency at the service, not only at the proxy, and reject beyond the bound rather than queueing without limit.
Measure p95 rather than mean, because clinical workflows care about the slow request in front of a patient.
Cache what is stable and expensive, and record the age of the cache in the response metadata.
How I do it
One trace of a real case with timestamps at every hop, before any document is written.
A findings list naming the defect, the system, the owner and the date, reviewed monthly.
No attestation I did not test, and no template sold as an assessment.
The service boundary
Decide what the service owns before writing a handler: a resource, a workflow, or a translation between two systems.
A service that owns too little becomes a proxy with validation; one that owns too much becomes a second monolith with a smaller deployment unit.
Write the boundary down, including what the service will never do, because the list of exclusions is what keeps it small.
Testing the layer
Test the contract with schema validation, the behaviour with integration tests against a real database, and the failures with fault injection.
Mock only what you do not own, and keep the mocks behind the same interface, so the test suite documents the dependency rather than hiding it.
Run the suite on every commit; a test suite that runs nightly tests yesterday's design.
Configuration and secrets
Configuration belongs in the environment or a managed store, never in the image, and secrets belong in the store with a rotation date.
Validate configuration at startup and fail loudly, because a service that starts with a missing variable fails at the first request instead of at boot.
Record which version of configuration a deployment used, since the interesting incidents are the ones where code did not change.
Observability that answers a question
Instrument the four things you will ask: why is it slow, who called, what did it decide, and what did it call next.
Traces answer the first and the last, logs answer the second and the third, and metrics tell you whether any of it is getting worse.
Keep the correlation identifier through every hop, because stitching an incident from timestamps alone takes an afternoon.
Dependency versions and drift
A service layer inherits security posture from its dependencies, and clinical services sit in an estate where a known vulnerability is an audit question rather than a developer preference. Pin versions, scan on every build, and treat base image age as a first-class metric. The scan result belongs with the deployment record, because the question after an incident is which hosts run the affected package, and the answer should be a query.
Upgrades should be routine, which means the test suite has to make them boring. An estate where upgrades are events accumulates deferred versions and then faces a coordinated upgrade under time pressure, which is exactly when the incompatibilities surface. Small, frequent upgrades with a green pipeline keep the service layer current at a cost that does not appear on any project plan.
Shutdown, deploy and in-flight work
Adding a handler is easy; draining one is not, and the failure appears only during deployment. A request that is processing a clinical write when the process receives a termination signal must be allowed to finish or must be recoverable, and the choice should be explicit. Timeouts on the proxy, the service and the database should be ordered so that the service hears about a slow dependency before the client gives up, and the ordering should be written down because reversing it by accident is easy.
Rolling deploys should be observable: the version in the health payload, the connection count as it drains, and the error rate during the window. Most deploy incidents are visible in those three numbers before anyone reports a symptom, and a one-line dashboard for the window pays for itself the first time a release goes badly. Blue-green is not necessary for a small estate; disciplined draining is.
Where the service layer should not reach
A service layer that starts making policy decisions about consent or eligibility becomes a second implementation of the rules the platform already holds, and two implementations diverge. The boundary should be that the service orchestrates and translates, while the policy owner answers the question. When that is not possible, the duplicated rule needs a test that both implementations share, or the divergence will be discovered by a clinician.
The same discipline applies to data: the service should not be the place where a copy of the patient record accumulates. Copies created for convenience are the data-flow map's recurring finding, and a service layer with a local cache of clinical data is a copy with a deployment pipeline. Cache reference data, not records, unless there is a written reason and a retention rule attached to it.
Versioning the service itself
A service layer changes faster than the contract it serves, and the two version numbers should not be confused. The API version is a promise to consumers; the service version is an internal fact about a deployment. Tracking both, and mapping which service version serves which API version, makes a rollback decision possible without archaeology and keeps the changelog honest about what consumers will actually see.
Where the service is stateless, rollback is a deployment; where it holds queues or scheduled work, rollback needs a plan for the work in flight. Writing that plan down before the first incident, with the specific steps and the person who decides, is the difference between a controlled reversal and a scramble. The service layer is where that decision usually lives, whether or not anyone has documented it.
Proof
- ONC (g)(10) self-test PASS, 317 of 317 subtests, April 2026 — public suite URL
- 67 public hostnames, 51 serving, one AWS account
- 104 clearinghouse enrolments across 53 jurisdictions
- USCDI v7 proposal — Patient Digital Identity Credential — listed at isp.healthit.gov
- SAM.gov UEI MVKQW9DKKGB8 · CAGE 20KM5 · NPI 1194645564
- AWS Business Associate Addendum active since 18 August 2026
Where this work is delivered
Engagements run from Las Vegas and reach across the valley: clients in Las Vegas, NV; Las Vegas, Nevada; Henderson; Clark County, Nevada; and North Las Vegas, Nevada — plus remote delivery nationwide.
How an engagement runs
1. Trace one real case
Follow a single patient or claim end to end with a timestamp at every hop, before any document is written.
2. Written findings
A findings list naming the defect, the system, the owner and the date.
3. Monthly review
Review the list monthly and check whether the dates held.
Frequently asked
What is this service?
This page describes charles trinh — fastapi service layer, las vegas nv — the scope, the failure modes it prevents and how the work is measured. It sits in the Data and Ledgers category at trinh.io.
Where is the work delivered?
Engagements run from Las Vegas, Nevada across the valley — Las Vegas, Henderson, North Las Vegas, Spring Valley, Paradise, Winchester, Sunrise Manor, Enterprise, Summerlin, Clark County — and remotely anywhere in the United States. On-site work in the Las Vegas valley, remote delivery elsewhere.
What does it cost?
Standard rate $195 per hour, committed $165 per hour at twenty hours or more per week for three months or more; $1,600 standard day, $1,350 committed day. Scoped in writing before work starts, fixed fee where the deliverable is defined.
Who is Charles Trinh?
A technology architect in Las Vegas, Nevada, working in healthcare identity, consent and interoperability. Not a physician, not a medical practice, and not affiliated with any other Charles Trinh.
How does an engagement start?
With one trace of a real case and a written findings list naming the defect, the system, the owner and the date. The first call is twenty minutes and free: 702-559-3489.
Engagement
Scoped in writing before work starts; fixed fee where the deliverable is defined. First call is 20 minutes and free. 702-559-3489 · charles@trinh.io
Talk to Charles
- Phone: 702-559-3489
- Email: charles@trinh.io
- Based in Las Vegas, Nevada · working remotely across the United States
Record
Profile
Healthcare technology architect working where federal regulation becomes production infrastructure. Built and operates a FHIR R4 clinical platform — SMART App Launch authorization server, patient and provider portals, SQLite — on a hardened single-host AWS estate of 67 public hostnames. The platform returned a self-test PASS on the ONC (g)(10) Standardized API test suite in April 2026, 317 of 317 subtests, publicly verifiable. Designed a consent architecture in which a permissioned ledger records patient grant, refusal and revocation as immutable events while all clinical data stays off-chain and encrypted per patient — no PHI on the ledger by design. Filed a proposed USCDI v7 data element with ONC on verifiable patient identity. Translates the Federal Register, HHS/CMS guidance and HITRUST requirements into architecture, controls and audit evidence.
Selected engineering scale
- Self-managed estate of 67 public hostnames, 51 serving, on one AWS account.
- FHIR R4 API with a SMART App Launch authorization server; patient and provider portals; an AI service layer; Hyperledger Fabric peer, orderer and CA; IPFS; a 337-table SQLite clinical store.
- Two permissioned distributed ledgers in production, one operating a consent registry that records grant, refusal and revocation with no PHI on chain.
- X12 005010 pipelines across eight transaction sets.
- Designed, built, deployed and operated end to end by one person.
Credentials and standards work
- Inferno (g)(10) self-test PASS, 317 of 317 subtests, April 2026 — the ONC Standardized API test suite. Standards validated: US Core 6.1.0, USCDI v3, SMART App Launch 2.0.0, Bulk Data 2.0.0. Public suite URL.
- USCDI v7 public comment submission, April 2026 — proposed Patient Digital Identity Credential under the Provenance data class, listed publicly on the ONC Interoperability Standards Platform.
- SAM.gov UEI MVKQW9DKKGB8 · CAGE 20KM5 · NPI 1194645564. AWS Business Associate Addendum active 18 August 2026.
Technical environment
AWS us-east-1 (compute, storage, messaging, SMS, email, voice) · Linux and systemd hardening · nginx · Fabric and EVM ledgers · FHIR R4 · X12 005010 · HL7 · SQLite · self-hosted mail, drive, search and monitoring · Git-based change control and CI release gates.