Let $S$ be the spectrum of a DVR, $X/S$ a flat finite type affine scheme. Fix a closed immersion $X\subseteq \mathbb{A}^n\_S$ and consider the closure $\bar X$ of $X$ in $\mathbb{P}^n\_S$. Then $\bar{X}$ is flat over $S$, as $X$ is dense in it. However, the boundary $Y = \bar X - X$ does not have to be flat over $S$ (see the examples below). 



> 
> Does every point of the closed fiber of $X$ have an open neighborhood $X'$ which can be compactified to a projective $\bar X'/S$ with $Y' := \bar X' - X'$ flat over $S$?
> 
> 
> 


**Example**. Take $X$ to be the generic point of $S$, $\bar X = S$ and $Y$ is the closed point of $S$. But as the closed fiber $X$ is empty, the condition is trivially satisfied.


**Example**. Let $X \subseteq{A}^2\_S$ be given by the equation $x = \pi y^2$ where $\pi$ is a uniformizer, then $\bar X \subseteq \mathbb{P}^n$ is given by $xz = \pi y^2$ and $Y$ is given by $z = 0 = \pi y^2$, a union of the $z=0$ line in the closed fiber and the section $(1:0:0)$, so not flat. Of course, $X$ is isomorphic to $\mathbb{A}^1\_S$, so we can find a compactification for which $Y$ is flat, namely $\bar X = \mathbb{P}^1\_S$.



Does there exist a relative compactification with flat boundary?
I believe the answer is no. All of the following will be relative to an algebraically closed field $k$. You may assume $k$ has characteristic $0$, but I think that is unnecessary (use the work of Stefan Schröer).


Let $g',g''>2$ be positive, distinct integers. Let $g$ be $g'+g''$. Let $\overline{M}\_g$ denote the Deligne-Mumford moduli stack of stable curves of (arithmetic) genus $g$. Let $\overline{M}\_g^o\subset \overline{M}\_g$ be the maximal open substack that is a scheme. In particular $\overline{M}\_g^o$ intersects the boundary divisor $\Delta\_{g',g''}$ since $g'\neq g''$; denote the intersection by $\Delta\_{g',g''}^o$. Denote the universal curve over $\overline{M}\_g^o$ by $$\pi:\mathcal{C}\to \overline{M}\_g^o.$$ Over $\Delta\_{g',g''}^o$, the restriction of the universal curve is a union of two proper closed subschemes, $\mathcal{C}'$ and $\mathcal{C}''$, intersecting along divisors, $Z'\subset \mathcal{C}'$, respectively $Z''\subset \mathcal{C}''$, such that $$(\pi':\mathcal{C}'\to \Delta\_{g',g''}^o,Z'), \ \text{resp.} \ (\pi'':\mathcal{C}''\to \Delta\_{g',g''},Z''),$$ is a family of stable, $1$-pointed curves of (arithmetic) genus $g'$, resp. $g''$. 


Let $\delta\_{g',g''}$ denote the generic point of $\Delta\_{g',g''}^o$, let $R$ be $\mathcal{O}\_{\overline{M}\_g^o,\delta\_{g',g''}}$, the local ring of $\overline{M}\_g^o$ at this codimension $1$ point. Of course $R$ is a DVR. Let $S$ be $\text{Spec}(R)$ with its natural morphism to $\overline{M}\_g^o$. Denote the closed point of $S$ by $0$, and denote the generic point by $\eta$. Let $$ \pi\_S:\mathcal{C}\_S\to S $$ be the base change of $\pi$ over $S$. Denote the closed fiber by $C\_0$, with its two irreducible components $C'\_0$ and $C''\_0$ as above. Let $X$ be $\mathcal{C}\_S \setminus C''\_0$.


By way of contradiction, assume that there exists a Zariski open subset $X'\subset X$ that intersects $C'\_0$ and that has a *projective* compactification $\overline{X}'\_S$ over $S$ whose boundary $Y'$ is flat over $S$. In particular, $Y'$ is finite over $S$. Denote by $$u:\widetilde{X}\to \overline{X}'$$ the normalization of $\widetilde{X}$. In particular, the generic fiber $\widetilde{X}\_\eta$ is isomorphic to the generic fiber $\widetilde{C}\_\eta$, i.e., $\widetilde{X}\_\eta \cong \mathcal{C}\_\eta$. Moreover, because the closed fiber $\widetilde{X}\_0$ is some compactification of an open subset of the genus $g'>0$ curve $C'\_0$, in particular $\widetilde{X}\_0$ contains no genus $0$ curves. Moreover, $\widetilde{C}\_S$ is regular.
Thus, by Abhyankar's lemma, etc., the isomorphism of generic fibers extends to an $S$-morphism, $$ v :\mathcal{C}\_S \to \widetilde{X}, $$ that is automatically projective. Moreover, this morphism contracts the irreducible component $C''\_0$ of the closed fiber of $\mathcal{C}\_S$. In particular, for every invertible sheaf $\mathcal{L}$ on $\widetilde{X}$, $v^\*\mathcal{L}$ restricts to the trivial invertible sheaf on $C''\_0$. In particular, since $\widetilde{X}$ is projective, there exists an invertible sheaf $\mathcal{L}$ that is ample, so that $v^\*\mathcal{L}$ is big.


This is impossible. By Franchetta's conjecture / Harer's theorem, the Picard group of $\mathcal{C}\_\eta$ is generated by the relative dualizing sheaf, and the Picard group of $\mathcal{C}\_S$ is generated by the relative dualizing sheaf together with the invertible sheaf $\mathcal{O}\_{\mathcal{C}\_S}(\underline{C'}\_0)$. The restrictions of these invertible sheaves to $C''\_0$ are $\omega\_{C''\_0}(\underline{Z}'')$ and $\mathcal{O}\_{C''\_0}(\underline{Z}'')$. But these are linearly independent in $\text{Pic}(C''\_0)$, i.e., the universal curve over the generic point of $\Delta\_{g',g''}$. Since $v^\*\mathcal{L}$ has trivial restriction to $C''\_0$, $v^\*\mathcal{L}$ is trivial. In particular, the restriction of $v^\*\mathcal{L}$ to the generic fiber $\widetilde{C}\_\eta$ is trivial. However, by construction, it is also big. This is a contradiction, proving that $\overline{X}'$ does not exist.


Observe the following points. First, $S$ is **not** Henselian. Second, the residue field of $S$ is **not** algebraically closed. Third, this argument only works if $\overline{X}'$ is a **projective** scheme; the argument fails if $\overline{X}'$ is only a proper algebraic space. So, if you really need something like this to hold, there are still directions to explore.


